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!
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.