permaculture playing cards
The moose likes JSF and the fly likes How to refresh the page after the reponse has been committed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "How to refresh the page after the reponse has been committed" Watch "How to refresh the page after the reponse has been committed" New topic

How to refresh the page after the reponse has been committed

Vij Kum

Joined: Feb 26, 2008
Posts: 1
Hi All,

I am using the following code to generate a downloable CSV file in one of the JSF projects:

FacesContext fc = FacesContext.getCurrentInstance();
HttpServletResponse response = HttpServletResponse)fc.getExternalContext().getResponse();
response.setHeader("Content-disposition", "attachment;
filename= Sample_Report.csv");
List list = (List) this.getSessionBean1().getDownloadFile();
ServletOutputStream out = response.getOutputStream();


for (int i=0;i<list.size();i++){


Now my requirement is, I want to refresh the page after above code is executed and file download popup window has come up. But currently my page is not getting refreshed after the file download popup window has come up.

Is there anybody who can help me in getting my page refreshed after the above mentioned code is executed and file download window has popped up.
This is a very critical requirement in my project and we are just stuck here.

Thanks in advance,
Vijay Kumar
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17421

Your problem is that JSF runs over HTTP and HTTP has a one-to-one request/response protocol.

Normally, you'd make a request (say, with a form submit or menu select) and the response would be a web page in your browser. But in your problem, the request is made and the response is the CSV file. Nothing further will happen until another request is made.

There are two popular ways to proceed.

1. Set up a download page in such a way that the user is made to understand that once the download is requested, they must click a link or button to proceed (or make another menu selection). Of course, this can be tricky, since users are infamous for not understanding things.

2. Place a client-side timed page refresh that will cause the file request page to be polled again after a few seconds and on the polling attempt, take the user to the next page.

You've almost got to present an explicit download page. If you just spin out CSV's from apparently random points in the app, it's likely to confuse people. This is one of the key differences between web apps and client-server apps.

On the plus side, almost all browsers will display some type of dialog either before or while downloading files (or both), so that helps reduce confusion.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: How to refresh the page after the reponse has been committed
It's not a secret anymore!