The following are basic navigation concepts in JSF:
Outcome strings are eventually translated into view ids that identify the target JSF page. Part of the translation involves expanding the outcome string into a path.
<h:commandButton value="Login" action="welcome"/>
Since the outcome string "welcome" does not have a suffix, the destination page welcome.xhtml is assumed.
Since "welcome" does not begin with "/", welcome.xhtml is assumed to reside where index.xhtml resides.
An outcome expression can invoke static or dynamic navigation.
In static navigation,
For example:
<h:commandButton value="Login" action="welcome"/>
In dynamic navigation, the outcome expression invokes an action method that, among other uses, allows navigation to depend on bean state.
An action method is a bean method that is usually invoked from a command button in a JSF page. It returns an outcome string to direct the navigation to the next page.
An action method is needed when either or both of the following are true.
A JSF page that uses action methods typically contains a tag like the following.
<h:commandButton value="button-label" action="#{bean-name.method-name(argument-list)}"/>
If literal string arguments are used they must be enclosed in single quotes. If the method has no arguments the parentheses can be omitted.
For example, suppose that the login application has a loginController bean with a method called verifyUser that needs to be run when the user attempts to login:
<h:commandButton label="Login" action="#{loginController.verifyUser}"/>
The appropriate bean class for bean-name should contain the following declaration.
public String method-name(parameter-declarations) { implementation-code return "outcome"; }
The method-name in this declaration should be identical to the method-name in the JSF page. The outcome should be the name of the next JSF page or a logical outcome.
For example, here is how the loginController bean's verifyUser method might look:
String verifyUser() { if (...) return "success"; else return "failure"; }