• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to refresh the page after the reponse has been committed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.setContentType("application/csv");
response.setHeader("Content-disposition", "attachment;
filename= Sample_Report.csv");
List list = (List) this.getSessionBean1().getDownloadFile();
ServletOutputStream out = response.getOutputStream();

out.println("Country");

for (int i=0;i<list.size();i++){
out.println(list.get(i).toString());
}

out.close();
fc.responseComplete();

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
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic