• 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

refresh a JSF page

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
My problem is that when I click the refresh button of the browser the last action performed again!
what is the solution to prevent the second request?

thanks
 
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
Welcome to the JavaRanch, Andolsi!

The browser refresh button is supposed to resubmit the request! JSF isn't any different than any other web technology in that way.

If that's a problem, you'll have to design your JSF code to detect the second request and act (or not act) in the way you want it to.
 
andolsi zied
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thnks for your answer, but hoow to detect the second request?
 
Tim Holloway
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
You need a stateful object to record the page requests in. If the backing bean that contains your action processor method is session scope, just put a counter or boolean property in there and check its current value when the action processor method is called. Update it after the first call so that you'll know the method had already been called once.
 
andolsi zied
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks again for answer but your solution prevent completely the action, but I want to prevent actions invoking only by the refresh button et not my button.
 
Ranch Hand
Posts: 199
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another way to deal with this problem is redirects. This works at least with JSF 2 but I am not sure if it works with JSF 1. In anycase with redirects the action you just performed leads to another URL (ie. a new request is performed on the fly) and if the user hits the refresh button after that only the new page is shown and the forms send is not performed again. This behavior is mainly implemented to make the JSF more bookmarkable so that you can for example bookmark the page you were redirected to.

So for example with this codeyou can accomplish this. But you must understand that if the request was made to a bean that is @RequestScoped then the new pageload does not have access to the values sent from the form. But there are alternative approaches to handle that (if it is necessary to access the original values at all!).
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Tim,Ilari,

"you can accomplish this. But you must understand that if the request was made to a bean that is @RequestScoped then the new pageload does not have access to the values sent from the form. But there are alternative approaches to handle that (if it is necessary to access the original values at all!). "

In my case, page have lots of requests that I want to retained in new page. could you please elaborate more on how to access the original values.
- thanks in advance.
 
Ilari Moilanen
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ashwani sinha wrote:
In my case, page have lots of requests that I want to retained in new page. could you please elaborate more on how to access the original values.
- thanks in advance.


I still use only JSF 2 so I do not know how this would work with JSF 1 but for example I use the temporay storage called Flash.
In the first action I use

and then in the receiving side in xhtml I use

and then in java code inside the loadDefaultValues method I get the contents with


Or if I just want to give simple parameters to receiving side I might use something like this (remove the blanks after & sign)

and then in the xhtml I use them with

These are maybe not optimized versions and there probably are easier ways of course...
 
Alas, poor Yorick, he knew this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic