How to declare the Navigation Rules for JSF?

How to declare the Navigation Rules for JSF?

A navigation rule specifies the JSF implementation which page need to send back to the browser after submitting a form. For instance, after the successful login, the page should to Main page or to return on the same login page. The following code snippet describes this.
<navigation-rule>
<from-view-id>/login.jsp</from-view-id>
<navigation-case>
<from-outcome>login</from-outcome>
<to-view-id>/main.jsp<to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>fail</from-outcome>
<to-view-id>/login.jsp<to-view-id>
</navigation-case>
</navigation-rule>

from-outcome to be match with action attribute of the command button of the login.jsp as:
<h:commandbutton value="Login" action="login"/>

Secondly, it should also match with the navigation rule in face-config.xml as
<managed-bean>
<managed-bean-name>user</managed-bean-name>
<managed-bean-class>core.jsf.LoginBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>

In the UI component, to be declared / used as:
<h:inputText value="#{user.name}"/>

value attribute is the name property of the user bean.

How to declare the Navigation Rules for JSF?

The Navigation rules indicate the JSF implementation to decide which page to navigate to after a certain action has been done on the browser like a form submission, etc.

1. The following example shows the usage of the navigation rules:
<navigation-rule>
<from-view-id>/login.jsp</from-view-id>
<navigation-case>
<from-outcome>loginv/from-outcome>
<to-view-id>/main.jsp<to-view-id>
</navigation-case>
</navigation-rule>

2. from-outcome should match with action attribute of the command button of the login.jsp:
<h:commandbutton value="Login" action="login"/>

3. Secondly, it should also match with the navigation rule in face-config.xml as
<managed-bean>
<managed-bean-name>user</managed-bean-name>
<managed-bean-class>core.jsf.LoginBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>

4. In the UI component, to be declared / used as:
<h:inputText value="#{user.name}"/>
What is JSF framework?
What is JSF framework? - JSF framework is an API for developing user interface components for web applications...
What does it mean by rendering of page in JSF?
What does it mean by rendering of page in JSF? - A JSF page has components that are made with the help of JSF library. The JSF components lke h:form...
What is JSF, JavaServer Faces?
What is JSF, JavaServer Faces? - JavaServer Faces (JSF) is a server side Java technology, developed by Sun Microsystems, in the field of web application development. ..
Post your comment