File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to refresh the page after the reponse has been committed

 
Vij Kum
Greenhorn
Posts: 1
  • 0
  • 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.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
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17646
39
Android Eclipse IDE Linux
  • 0
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic