my dog learned polymorphism*
The moose likes JSF and the fly likes refresh a JSF page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "refresh a JSF page" Watch "refresh a JSF page" New topic
Author

refresh a JSF page

andolsi zied
Greenhorn

Joined: Oct 05, 2010
Posts: 3
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
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15950
    
  19

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
andolsi zied
Greenhorn

Joined: Oct 05, 2010
Posts: 3
thnks for your answer, but hoow to detect the second request?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15950
    
  19

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

Joined: Oct 05, 2010
Posts: 3
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.
Ilari Moilanen
Ranch Hand

Joined: Apr 15, 2008
Posts: 198
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!).
ashwani sinha
Greenhorn

Joined: Dec 12, 2013
Posts: 1
@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

Joined: Apr 15, 2008
Posts: 198
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...
 
wood burning stoves
 
subject: refresh a JSF page
 
Similar Threads
How can I control Eclipse Refresh ?
Upload attachment to QC [Quality Center] using java
How do I redirect to "login.jsp" after 5 seconds?
JARS are visible threrough RAD 7.0
stats from Paul's site