Answers

Question and Answer:

  Home  Java Server Faces

⟩ Do you know 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.

 149 views

More Questions for you: