• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

JSF page refresh after csv file download.(POI)

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

See http://wiki.apache.org/myfaces/JavascriptOpenNewWindow for more information
 
ranjan Khaba
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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().
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.



 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 94
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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


 
I miss the old days when I would think up a sinister scheme for world domination and you would show a little emotional support. So just look at this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic