• Post Reply Bookmark Topic Watch Topic
  • New Topic

downloading a file by redirecting to servlet from a Portlet JSF page  RSS feed

 
Kunal Okhandiar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. I have a commandLink in a JSF page in a portal environment. On clicking it, I redirect to a servlet (by calling facesContext.getExternalcontext().sendRedirect(//Servlet URL//)).

2. the servlet is created for downloading an excel file from the server.
3. A Save As File dialog opens up with the JSF Portal page in the background.

This works fine, but when I have downloaded the file, I find that when I click on any action component on the portal JSF page, it just refreshes the page instead of performing the action. I have to click that action component again for it to work.

Wehn I used a PhaseListener to track the JSF lifecycle, I find that after the redirect, Step 6, i.e.renderResponse phase is missing. Could this be the issue? How can I resolve this?
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSF itself doesn't manage the file download. For that, your servlet takes over, so that's why the missing renderResponse. The file-downloading servlet rendered the response.

Most HTTP is done in back-and-forth conversations. What comes back from the server provides the basis for what goes down to the server on the next request. In the case of a file download, however, the trip is one-way. Obviously you're not going to re-upload the file that came to you!

What that means, is that although the file is sent to you, your browser is still sitting on the upload request page, since only one response per request is possible, and in this particular request, that response is the file.

I'm not really sure why you're having to click twice. But I suspect that your browser lost the input focus while all this was going on and the first click was required to get the focus back. You can verify that by clicking somewhere outside of the action controls and then clicking on a control (the title bar typically highlights when a window gets focus, too). If the control files without needing a third click, then that's basically what it is.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!