Navigations can be handled in JSF by writing methods in the managed bean. These methods should be public, take no parameters and should returns an object or a view name. The method is invoked in the action attribute of the JSF page.

Let’s understand this concept more clearly with an example.

Create addmob.xhtml as


Here we are invoking the add method of the mobile managed bean in the action attribute to render the page on click of submit.

Create viewmob.xhtml that is called from the add method of the bean and displayed.


Create the managed bean as;

Note that we are returning the viewmob page in the add method which displays the details of the mobile entered by the user upon click of submit.

Now run the application and you should see below response pages.


On clicking submit button in above page, you should get below output.


Another way of handling navigation through a method is by specifying a string outcome in the method and map the returned string to a JSF page. This is done by making an entry in faces-config.xml file.

Create addmobstring.xhtml as;


Create viewmobstring.xhtml as


Create the managed bean as;

Here we are returning the string “for” from the add method.

Now lets create the faces-config.xml as;

If we run the application , we get the expected behavior as shown in below images.


Upon clicking submit button, you should see below response page.


Finally, below image shows the project structure in Eclipse.


Please download the project zip from below link and play around with it to learn more.

By admin

Leave a Reply

%d bloggers like this: