0

I want to invoke two methods in two other tags after h:commandLink click. I use JSF2 and RichFaces 4.3.7.

<a4j:jsFunction name="print" 
    action="#{PDFReportsMBean.printSelectedScannedDoc}"
     status="waitStatus">
</a4j:jsFunction>

<h:commandLink value="${msg['page.dfeOper016form.button.printAll']}" 
    target="_blank"  
    disabled="#{not PDFReportsMBean.selectedAnyDocs}"
    action="#{PDFReportsMBean.prepareData}">
</h:commandLink>

<a4j:ajax event="click" oncomplete="print()"/>

This code does not work... Coluld anyone help me?

Aritz
  • 30,971
  • 16
  • 136
  • 217
karolus
  • 21
  • 5

1 Answers1

0

It's not possible to perform a file download using Ajax as you're trying to do. Ajax uses javascript under the covers, which has limitations of file writing permissions. Your best chance is to wrap the whole logic in a single method or, alternativelly, use an actionListener:

<h:commandLink value="${msg['page.dfeOper016form.button.printAll']}" 
    target="_blank"  
    disabled="#{not PDFReportsMBean.selectedAnyDocs}"
    actionListener="#{PDFReportsMBean.prepareData}" 
    action="#{PDFReportsMBean.printSelectedScannedDoc}"/>

See also:

Community
  • 1
  • 1
Aritz
  • 30,971
  • 16
  • 136
  • 217
  • It is not solution for me bacuse after PDFReportsMBean.prepareData and before 'PDFReportsMBean.printSelectedScannedDoc' method I must re-render some elements in my page... – karolus Aug 12 '14 at 07:46
  • Which behaviour are you expecting? Something similar to the Primefaces' [download monitor](http://www.primefaces.org/showcase/ui/file/download.xhtml)? – Aritz Aug 12 '14 at 07:49
  • In the `PDFReportsMBean.printSelectedScannedDoc` I invoke : `HttpServletResponse response = (HttpServletResponse) externalContext.getResponse(); response.reset()` and I must rerender elements before `PDFReportsMBean.printSelectedScannedDoc`... I cant not change `PDFReportsMBean.printSelectedScannedDoc` method code because my app uses this method in a few places... – karolus Aug 12 '14 at 07:56