This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSF and the fly likes JSF page refresh after csv file download.(POI) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF page refresh after csv file download.(POI)" Watch "JSF page refresh after csv file download.(POI)" New topic
Author

JSF page refresh after csv file download.(POI)

ranjan Khaba
Greenhorn

Joined: Jan 16, 2008
Posts: 22
My JSF project has a requirement to reload a page after an attachment is downloaded I am using a ServletOutputStream print method to write the CSV file. My requiremtn is first the pop up should come up and then the page should get refreshed.
The logic to refresh the page after some time cannot be implemented because the user is not allowed to perform any of the operation if the “current operation is not complete”.

Thanks in advance,
Ranjan
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
You can send only one response per request.
Here you want to send two responses: one for the CSV file and another for the reload.
So you need to fire two requests. You can use Javascript to fire the another request.
ranjan Khaba
Greenhorn

Joined: Jan 16, 2008
Posts: 22
Hi,

thanks for the response,

I need a clarification, firing two respnse means, I have to call a java script method to send a response from the servlet and response for writting the csv file.

I will be very happy, If you share me some link or some code snippet.

Thanks in advance,

Ranjan
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60789
    
  65

Please take the time to choose the correct forum for your posts. This forum is for questions on Servlets.

For more information, please read this.

This post has been moved to a more appropriate forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Leinad Jan
Greenhorn

Joined: Feb 18, 2009
Posts: 28
The multiple request launch with Javascript is working fine on a local server, but it doesn't work well on distant server. Everytime I did that, the second request is freezing the page waiting for its response. And I'm losing the response of the first request, losing the file I was downloading.
Pari Gandhi
Greenhorn

Joined: Feb 26, 2009
Posts: 10

See http://wiki.apache.org/myfaces/JavascriptOpenNewWindow for more information
ranjan Khaba
Greenhorn

Joined: Jan 16, 2008
Posts: 22
Thanks for the reply,

When I clicked the export button of the JSF page, the eventhandler method redirect it to a servlet, the servlet used the "content-disposition" Header. There for the pop-up for the csv file download comes up. My requiredment is I want to get my page refresh after the user clicked /open/save/cancel button. I am not able to relate with my requiredment and the solution provided above. Excuse me if I am not putting my problem properly.



thanks
Ranjan
Leinad Jan
Greenhorn

Joined: Feb 18, 2009
Posts: 28
The pop up doesn't seems to be a bad solution. You create a popup that will close itself and that will call the file while the rest of the page is free to be reloaded. I might try something like that.

Thank you.
ranjan Khaba
Greenhorn

Joined: Jan 16, 2008
Posts: 22
Thanks for reply,

The pop-up is not created by me, it comes because of the header "content- disposition" from the servlet. So I do not have the means to reload the page.

any sugggestion....

thanks
Ranjan
ranjan Khaba
Greenhorn

Joined: Jan 16, 2008
Posts: 22
I have search a lot and get some suggestion, but seems there is no proper solution.
Some give the suggestion regarding the
-multi part response ---IE has some limitation.
-Page refresh automaticcaly----cannot be used according to my requirement.
-sending two request-- so on.
Still, I am not able to find the correct solution according to my requirement. Is it a limitation.

One request - One Response

Thanks
ranjan
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
As said, you need to fire two requests to get two responses.
Use the link/button's default action to navigate to another page.
Use the link/button's onclick to start the download using window.open().
Matt Sigma
Greenhorn

Joined: Nov 25, 2011
Posts: 1
I had the same problem. This is how i solved it:



So the important line is:
response.setHeader("Refresh", "3; url = pageToRefresh.jsf");

We are limited by sending only one response. In my case I need to show the updated 'date last download' of the data file.
and the date last download is only generated after the file has been created and sent to the user.
thus we append the "Refresh" Header with the streamed file in the response.

In this case the number 3 tells the page to wait 3 seconds before refreshing the page.
So the user downloads the pdf (clicks save, chooses a directory to save it in, clicks ok)
Then the web page waits 3 seconds before refreshing the page showing the updated date last download.

Simple solutions are always the best ones.



kunal patel
Greenhorn

Joined: Jan 09, 2012
Posts: 1
Hi Matt Sigma ,

I have tried your approach:
response.setHeader("Refresh", "3; url = pageToRefresh.jsf");

But it is not working for me..

I have written below code to refresh seam page:

req = (HttpServletRequest) fc.getExternalContext()
.getRequest();
response.setHeader("Refresh", "1; url = "+req.getRequestURL()+"");

Let me know if any mistake or any suggestions.

Thanks,
Kunal
Yogesh Lonkar
Ranch Hand

Joined: Jul 17, 2012
Posts: 94

i find some non appropriate solution for this problem
what i did was in FORM after user clicks on submit button i added 1 more attribute in it
<s:submit ----your attributes------- onmouseup="refresh(2000) "/>
and in head tag of JSP page i added this
<script type="text/javascript">
function refresh (timeoutPeriod){
refresh = setTimeout(function(){window.location.reload(true);},timeoutPeriod);
}
</script>
it reloads the page in 2 seconds after submiting of form but if download POP did not appear before that that download get's canceled

if your download size is large you can adjust time as per your needs it's not perfect solution for this problem but rather a Duck Tape method



Learning some thing New Every Day
 
Don't get me started about those stupid light bulbs.
 
subject: JSF page refresh after csv file download.(POI)
 
Similar Threads
Mutiple threads on a single reqest
popup window in JSF
How to refresh the page after the reponse has been committed
How to refresh a JSF page after downloading a CSV file.(content-disposition)
page refresh help required