Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JSF forward Vs redirect

607283May 12 2008 — edited Feb 22 2010
This is some info i feel will be quite useful for us newbies. I did a bit of searching on the forum and couldn't come up with the right topics, when i googled it though i got exactly what i was looking for. For the benefit of forum lovers , a basic solution for an even more basic requirement:-

My problem:-

I have a generic error page. Under some circumstances , i populate my error messages on the faces context and wish to " forward " to another page , not the usual redirect that jsf conveniently provides us with.

To redirect typically you would use:-
facesContext().getExternalContext().redirect("errorPage.jspx");
facesContext().responseComplete();

If you had populated the error messages on the faces context previously and wish for these to show up on the error message, sorry won't happen. A redirect = close current request. Usually you would let faces handle this by providing good navigatino rules in your faces-config file etc etc.

If however you wish to only do a forward and not redirect you should do the following:-
JSFUtils.getFacesContext().getExternalContext().dispatch("errorPage.jspx");
JSFUtils.getFacesContext().renderResponse();

Another better approach would be to populate the messages on the process scope and then use this , but this may not always be the case, as you would prefer to pick it up only from the request ( as mentioned in reference link)


Reference link :-
http://forum.java.sun.com/thread.jspa?threadID=659090&messageID=3872902
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 22 2010
Added on May 12 2008
4 comments
8,030 views