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
posted
0
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.
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.
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.
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
posted
0
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
posted
0
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
posted
0
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
posted
0
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
posted
0
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
posted
0
Hi Matt Sigma ,
I have tried your approach:
response.setHeader("Refresh", "3; url = pageToRefresh.jsf");
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