Instead of adding ?faces-redirect=true to each action in my , I would like to use it o...">

Consequences of using JSF <redirect / ">

Instead of adding ?faces-redirect=true to each action in my <h:commandButton /> , I would like to use it once for good in faces-config.xml , but I'm still not sure about the consequences of using it.

It states that redirect will be used instead of forward . But what are the consequences? This is bad practice, does it affect persistence and servlet requests and responses?

For me, using REDIRECT is only available to display URLs correctly. I intend to use something like this:

 <navigation-rule> <from-view-id>/*</from-view-id> <navigation-case> <from-outcome>*</from-outcome> <redirect /> </navigation-case> </navigation-rule> 

Thanks so much for the guidance.

+4
source share
1 answer

Forwarding basically tells the browser to create a new HTTP GET request. Thus, the entire request (and view) covered by beans will be split at the point at which the redirection is performed. Any request data that was set during the validity of the form will no longer be available in the new request. If this is a serious problem, it is best to put it in the session area, but it has more serious consequences: any change in the bean session area is reflected in all actions that occur in different browser tabs / windows of the same session. An alternative is to pass the data of interest as a query string to the forwarding URLs, but this one is simple bulky and ugly.

If you really have no data that needs to be stored in a redirected request, you can do this. But this poses a new question: why do you use a POST request at all? Are you sending something to the server? Or do you use this to cleanly navigate pages? This question makes me think this is the last. In this case, you should not use POST to navigate pages, but simply GET. This can be achieved by <h:button> (and its equivalent to a link <h:link> )

 <h:button value="Next page" outcome="nextpage" /> 

If this is actually the first, I would just stick to it. You do not want to bookmark POST requests.

See also:

+5
source

All Articles