Wednesday 15 May 2013

jsf - Close PrimeFaces dialog after OmniFaces sendFile -



jsf - Close PrimeFaces dialog after OmniFaces sendFile -

i'm trying create <p:ajaxstatus /> indicator when downloading file using omnifaces faces.sendfile function. when user clicks export link dialog tells them file beingness created (because can take sometime depending on info size), after file downloads message closes.

in xhtml:

<p:dialog widgetvar="exceldialog" modal="true"> <h2>building spreadsheet</h2> </p:dialog> <h:commandlink value="export" action="#{resultsbean.excelexport}" onclick="exceldialog.show();" />

and in viewscoped bean:

public void excelexport() throws ioexception { excelexport ee = new excelexport(results); faces.sendfile(ee.getfile(), true); }

what can't figure how close dialog after response complete.

i've tried using primefaces requestcontext (which should work non-ajax requests) not work. wonder if because faces.sendfile calls facescontext.responsecomplete() before requestcontext used.

public void excelexport() throws ioexception { excelexport ee = new excelexport(results); faces.sendfile(ee.getfile(), true); requestcontext c = requestcontext.getcurrentinstance(); c.execute("pf('exceldialog').hide();"); } jsf 2.1 primefaces 4.0 omnifaces 1.8

i wonder if because faces.sendfile calls facescontext.responsecomplete() before requestcontext used.

it prevents download file content beingness corrupted because else's trying write more info response.

you're trying send multiple responses on single request. not possible. can send 1 response per request. if effort possible, download file content corrupted because xml code representing primefaces ajax response appended end of download file content.

you need send 2 requests whereby 2nd request fired automatically on end of 1st request. 1st request should prepare file , park somewhere (property of @viewscoped bean?) , close dialog , trigger 2nd request. 2nd request should download parked file. 1st request can done ajax <p:commandbutton>, 2nd request must synchronous obvious reasons. can perform 2nd request using <h:commandlink> hidden using css.

e.g.

<h:form id="formid"> <p:commandlink value="export" action="#{resultsbean.excelexport}" onclick="exceldialog.show();" oncomplete="exceldialog.hide(); document.getelementbyid('formid:linkid').click();" /> <h:commandlink id="linkid" action="#{resultsbean.exceldownload}" style="display:none;" /> </h:form>

with

private file excelfile; public void excelexport() { excelfile= new excelexport(results).getfile(); } public void exceldownload() throws ioexception { faces.sendfile(excelfile, true); }

jsf primefaces omnifaces

No comments:

Post a Comment