-
1. Re: [Tree] how to download file on nodeSelectListener
nbelaevski Mar 26, 2009 7:58 AM (in response to lmk)Hello,
It is not possible to download file by AJAX request directly. Try redirecting to file. -
2. Re: [Tree] how to download file on nodeSelectListener
lmk Mar 26, 2009 9:35 AM (in response to lmk)"nbelaevski" wrote:
Hello,
It is not possible to download file by AJAX request directly. Try redirecting to file.
how Can I redirect to file ..?
thanks -
3. Re: [Tree] how to download file on nodeSelectListener
lmk Mar 26, 2009 12:51 PM (in response to lmk)"lmk" wrote:
"nbelaevski" wrote:
Hello,
It is not possible to download file by AJAX request directly. Try redirecting to file.
how Can I redirect to file ..?
thanks
I tried :<a4j:support event="onselected" action="#{fTPViewerTree.downloadSelectedFile}"> </a4j:support>
and after I use redirect on navigation case.
but nothing happeng, the file is not displayed on the navigator nor downloaded.. -
4. Re: [Tree] how to download file on nodeSelectListener
nbelaevski Mar 26, 2009 7:38 PM (in response to lmk)Please post action code.
-
5. Re: [Tree] how to download file on nodeSelectListener
lmk Mar 27, 2009 5:14 AM (in response to lmk)here the action code
public String downloadSelectedFile() { String res = null; if (getSelectedFile() != null) { FileObject file = getSelectedFile().getFile(); FacesContext context = FacesContext.getCurrentInstance(); ExternalContext external = context.getExternalContext(); HttpServletResponse response = (HttpServletResponse) external.getResponse(); response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", "attachment; filename=" + file.getName() + ""); OutputStream out; try { out = response.getOutputStream(); out.write(file.getContent()); out.close(); context.responseComplete(); } catch (IOException e) { e.printStackTrace(); } res = "success"; } return res; }
navigation :<navigation-rule> <from-view-id>/ftp_files.xhtml</from-view-id> <navigation-case> <from-outcome>success</from-outcome> <to-view-id>/ftp_files.xhtml</to-view-id> <redirect/> </navigation-case> </navigation-rule>
regards! -
6. Re: [Tree] how to download file on nodeSelectListener
nbelaevski Mar 27, 2009 8:05 AM (in response to lmk)You are calling FacesContext.responseComplete(), that's why redirection does not occur. Please try to use javax.faces.context.ExternalContext.redirect(String).
-
7. Re: [Tree] how to download file on nodeSelectListener
lmk Mar 27, 2009 10:23 AM (in response to lmk)"nbelaevski" wrote:
You are calling FacesContext.responseComplete(), that's why redirection does not occur. Please try to use javax.faces.context.ExternalContext.redirect(String).
you mean I do not use JSF navigation case and I do redirect like:external.redirect("/ftp_files.xhtml");
?
I'll test and let you know.. -
8. Re: [Tree] how to download file on nodeSelectListener
lmk Mar 27, 2009 10:37 AM (in response to lmk)It does not work.
-
9. Re: [Tree] how to download file on nodeSelectListener
lmk Mar 27, 2009 11:58 AM (in response to lmk)I add a commandButton inside treeNode to send non ajaw request but how I can call nodeSelectListener on button click.
<rich:treeNode type="file" nodeSelectListener="#{fTPViewerTree.processFileSelection}"> <h:outputText value="#{item.name}" styleClass="text_bold" /> <h:commandButton action="#{fTPViewerTree.downloadSelectedFile}" value="dowload" > </h:commandButton> </rich:treeNode>
regards! -
10. Re: [Tree] how to download file on nodeSelectListener
nbelaevski Mar 27, 2009 3:47 PM (in response to lmk)Works perfectly for me:
public void onSelect(NodeSelectedEvent event) throws IOException { FacesContext facesContext = FacesContext.getCurrentInstance(); facesContext.getExternalContext().redirect("/tree-demo/pages/ajaxTable.jsf"); facesContext.responseComplete(); }
-
11. Re: [Tree] how to download file on nodeSelectListener
lmk Mar 30, 2009 4:30 AM (in response to lmk)Still not work for me, did you try to download a file?
You advice to not call responseComplete"nbelaevski" wrote:
You are calling FacesContext.responseComplete(), that's why redirection does not occur. Please try to use javax.faces.context.ExternalContext.redirect(String). -
12. Re: [Tree] how to download file on nodeSelectListener
nbelaevski Mar 30, 2009 8:35 AM (in response to lmk)"lmk" wrote:
It's redirecting to the proper page, I think file will be also downloaded ok.
Still not work for me, did you try to download a file?"lmk" wrote:
That's for the case of using application navigation rules, but action is sending redirect internally, so it's still necessary.
You advice to not call responseComplete"nbelaevski" wrote:
You are calling FacesContext.responseComplete(), that's why redirection does not occur. Please try to use javax.faces.context.ExternalContext.redirect(String). -
13. Re: [Tree] how to download file on nodeSelectListener
lmk Mar 30, 2009 8:55 AM (in response to lmk)Sorry I dont understand what you mean..
I'd like to dowload file, I have byte array I'd put the byte array on the response and return to the page, the file will be downloaded. The is a text file..with data/ini .. extension..
how Can I send no-ajax request from the Tree to have a normal behaviour for download file..?
thanks. -
14. Re: [Tree] how to download file on nodeSelectListener
nbelaevski Mar 30, 2009 9:40 AM (in response to lmk)Redirect the request to some URL in your application that will output file contents. You can create phase listener that will render files.