On Java Development

All things related to Java development, from the perspective of a caveman.

JSF 2.0 Page Navigation

without comments

Introduction

This post shows how to perform page navigation using JSF 2.0 and above, which is much easier than it was using earlier versions.

Navigation is most often conducted using a menu option but links and buttons can also be employed. The example presented uses a menu option and an Action Listener method that allows navigation from page 1 of the application to page 2. The actionListener tag is used to indicate the managed bean method to be called when the menu option is selected.

The method that is called is presented below. Being an action listener it accepts an ActionEvent object, which is not referenced by the logic.

The process begins by digging into the FacesContext class to get to the ExternalContext that provides page redirect support. As seen, navigation to the desired page is a simple matter of providing the path to the page in addition to providing a parameter. The path is relative to “src/main/wepapp“.

When the menu option is selected, the session redirects to the page.

Written by admin

March 26th, 2014 at 9:56 am

Leave a Reply

You must be logged in to post a comment.