This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to refresh the page after the reponse has been committed  RSS feed

Vij Kum
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18705
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!