javascript - Is it possible to download a file using PrimeFaces RemoteCommand? -


i have page table has optional columns user can hide , show. when user chooses download content of table via link @ bottom of table, want send them content of displayed columns.

in order need use remote command since regular commandlink not accept js parameters tell server columns being displayed.

my problem file not being downloaded. when debug, sever method , go through whole process completely, when return browser see content of file in network tab in chrome, file not being downloaded , instead page being refreshed. if put return false after invoke command, see file in network tab in chrome, , page not refresh nothing happens. tried use onsuccess or oncomplete events, not seem work expect.

can done using jsf or have write servlet this?

here code: link

<h:commandlink value="download data" onclick="invokedownload();return false;" /> 

the invoke js method:

var invokedownload = function() {         var columnlabels = getvisiblecolumns().tostring();         downloadtabledata([{ "name": "columnlabels", "value": columnlabels     }]);     } 

the remote command:

<p:remotecommand name="downloadtabledata" action="#{mybean.datatable.download()}" process="@this"/> 

no. <p:remotecommand> fires ajax request. can not download files ajax. ajax executed javascript code, has obvious security reasons no facilities force save as dialog data held in javascript variable.

just fire synchronous request. can let js populate hidden input fields having same names request parameters you're attempting pass through.

<input type="hidden" id="name" name="name" /> <input type="hidden" id="value" name="value" /> <h:commandlink value="download data"      onclick="populatedownloaddata()"     action="#{mybean.datatable.download()}" /> 
function populatedownloaddata() {     var columnlabels = getvisiblecolumns().tostring();     document.getelementbyid("name").value = "columnlabels";     document.getelementbyid("value").value = columnlabels; } 

those params way strange. perhaps you're confused <p:remotecommand> examples. i'd have used single request parameter name columnlabels.

<input type="hidden" id="columnlabels" name="columnlabels" /> <h:commandlink value="download data"      onclick="populatedownloaddata()"     action="#{mybean.datatable.download()}" /> 
function populatedownloaddata() {     var columnlabels = getvisiblecolumns().tostring();     document.getelementbyid("columnlabels").value = columnlabels; } 

Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -