File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes How to redirect in a jsf? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "How to redirect in a jsf?" Watch "How to redirect in a jsf?" New topic

How to redirect in a jsf?

Richard Green
Ranch Hand

Joined: Aug 25, 2005
Posts: 536
User clicks on a menu item that takes him to a.jsp. a.jsp should check whether a particular attribute exists in the session or not. If it doesn't it should redirect the user to b.jsp.

I know how to do this with a servlet (using requestdespatcher). But JSF doesn't have a front controller (it has backing beans only). So how do i go about doing this?

MCSD, SCJP, SCWCD, SCBCD, SCJD (in progress - URLybird 1.2.1)
Jithesh Kozhipurath
Ranch Hand

Joined: Aug 27, 2003
Posts: 76
The JSF can work similar to a Servelet.
You can specify the navigation rules in the faces-cofig.xml
In this xml file you can specify the navigation case and outcome value
and to view id.
Using this outcome value you could navigate to different pages. The value in this outcome field can be a scope variable. This can done using the #{} construct.

I m not very sure that this will satisfy the req. Please try.

Jithesh K
Richard Green
Ranch Hand

Joined: Aug 25, 2005
Posts: 536
Brian Smith
Ranch Hand

Joined: May 20, 2005
Posts: 63
Just like Jithesh said, navigation is handled in the faces-config.xml file. When you preform an action on a page by clicking a link/button whatever, you define a navigation rule in the faces-config. That navigation rule is set to forward by default but can be set to redirect explicitly. Here is a link to the book Core JavaServer Faces. Quite a few chapters are available for free.

Here is the chapter on navigation

Toward the end of the chapter, they talk about redirects
I agree. Here's the link:
subject: How to redirect in a jsf?
It's not a secret anymore!