0

I'm using BalusC's FileServlet example:

http://balusc.blogspot.com/2007/07/fileservlet.html

I'm able to get it to work, however, I would like to call a bean function before the download takes place. Is there a way to make that work? I tried with a4j:support and I also tried with h:commandLink and neither worked. Any help is appreciated!

KVISH
  • 12,923
  • 17
  • 86
  • 162

1 Answers1

1

You could do the file download job in bean's action method instead. For some concrete examples, see this answer: How to provide a file download from a JSF backing bean?

You only need to make sure that the request isn't made by Ajax, because the JavaScript language, who is responsible for handling the Ajax request, does not have any facilities to force a Save As dialogue for security reasons. So, use a plain <h:commandLink> or <h:commandButton> for this.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • But seems this is using tr:fileDownloadActionListener, is there a way to use the servlet as described above and calling the bean function? – KVISH Mar 29 '12 at 14:25
  • 1
    It doesn't matter. Just use ``. As to using the servlet, there are ways but it's unnecessarily overcomplicated as you basically need to send 2 HTTP requests in a single click of which one is performed by JavaScript. – BalusC Mar 29 '12 at 14:34
  • Hi, I tried following the documentation on the trinidad website, but getting errors loading the jar files: `SEVERE: Error Loading Library: jar:file:/Users/Documents/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/project/WEB-INF/lib/trinidad-impl-2.0.1.jar!/META-INF/tr.taglib.xml` Is there a comprehensive example on this? – KVISH Mar 30 '12 at 00:24
  • I think you totally misunderstood the linked question/answer. OP was just asking how to achieve the same as Trinidad's file download component with plain JSF. My answer in there has shown that. You don't need to install Trinidad or something. Just write the backing bean code as shown in my answer and invoke that form ``. – BalusC Mar 30 '12 at 00:30
  • Never mind, I found an alternate solution to my problem, thanks! – KVISH Mar 30 '12 at 01:26
  • The problem underlying here was that commandlink and commandbutton were not working in h:dataTable – KVISH Mar 30 '12 at 01:37
  • That can happen if the value of the datatable is dependent on a request based condition and the bean is not in the view scope and/or the data loading logic is wrong. See also point 4 of http://stackoverflow.com/questions/2118656/hcommandlink-hcommandbutton-is-not-being-invoked – BalusC Mar 30 '12 at 02:35
  • Huh? Why did you tag the question with `[jsf-2.0]`? This was misleading information in your question. For JSF 1.x you must tag with `[jsf]` or maybe `[jsf-1.2]` instead. – BalusC Mar 30 '12 at 03:13