-
1. Re: How to avoid page reload on a4j:htmlCommandLink ?
nbelaevski May 28, 2009 3:46 PM (in response to avaldez314)Hi,
Use a4j:commandLink. -
2. Re: How to avoid page reload on a4j:htmlCommandLink ?
avaldez314 May 28, 2009 4:55 PM (in response to avaldez314)"nbelaevski" wrote:
Hi,
Use a4j:commandLink.
Hello, using a4j:commandLink was my very first choice but this link starts a file download and I could not make it work with an a4j:commandLink.
To start the file download I'm using the method described at:
http://ahoehma.wordpress.com/2008/03/31/jsf-file-download/
If the a4j:htmlCommandLink can't be used without a page reload, do anyone know other way to start a file download from a managed bean (not a servlet) without doing a page reload? (I can't use a simple html link to the file because it's retrieved from a database). -
3. Re: How to avoid page reload on a4j:htmlCommandLink ?
nbelaevski May 28, 2009 5:52 PM (in response to avaldez314)It shouldn't replace page contents. What is file type?
-
4. Re: How to avoid page reload on a4j:htmlCommandLink ?
avaldez314 May 29, 2009 2:12 PM (in response to avaldez314)"nbelaevski" wrote:
It shouldn't replace page contents. What is file type?
It happens with all extensions I have tried (i.e. pdf, xls).
I just tried again, I replaced the a4h:htmlCommandLink for a4j:commandLink, then an AJAX request is made to call the actionListener, the file is retrieved and sent to the browser but the file content is rendered (raw) in the browser screen.
I checked that the contentType attribute in the HttpServletResponse object is set to the correct type, but anyway when using a4j:commandLink the file content is sent directly to the browser screen.
This is a snippet of how I'm setting the HttpServletResponse response object:HttpServletResponse response = (HttpServletResponse) context .getExternalContext().getResponse(); response.setHeader("Pragma", "no-cache"); response.setDateHeader("Expires", 0); response.setContentType(contentType); response.setHeader("Content-Disposition", "attachment; filename=\""+ filename + "\""); // feed the file into the response outputStream in response.getOutputStream() // ... context.responseComplete();
Any suggestion? -
5. Re: How to avoid page reload on a4j:htmlCommandLink ?
nbelaevski May 29, 2009 2:49 PM (in response to avaldez314)Sorry, I was not precise, a4j:commandLink doesn't allow files downloading. Use a4j:htmlCommandLink for that. Try not setting content-type at all.
-
6. Re: How to avoid page reload on a4j:htmlCommandLink ?
avaldez314 May 29, 2009 3:24 PM (in response to avaldez314)"nbelaevski" wrote:
Sorry, I was not precise, a4j:commandLink doesn't allow files downloading. Use a4j:htmlCommandLink for that. Try not setting content-type at all.
Using a4j:htmlCommandLink the download works correctly but the page is reloaded and the browser shows the top of the page, not preserving the scroll position where it was before start the download.
This is the reason why I was asking for a way to avoid the page reload in the a4j:htmlCommandLink.
If avoiding the page reload isn't possible, do you know any workaround to this situation? -
7. Re: How to avoid page reload on a4j:htmlCommandLink ?
avaldez314 May 29, 2009 3:36 PM (in response to avaldez314)I'm sorry, I forgot something important:
When doing the download with the a4j:htmlCommandLink the download starts correctly and the page is not reloaded.
But in case that of a database failure a message should be displayed to the user to inform about the error, I'm showing that error with a <rich:message> inside the <a4j:form>.
When there is a message to show, then the page is reloaded and the scroll position is not preserved. I though that <rich:message> would be updated in an AJAX request without a page reload.
Please, take a look at my first post, there I show how I'm trying to do it.
I appreciate a lot your help, really :-)