<h:commandButton value="label-expression" action="outcome-expression"/>
The outcome-expression is a string-valued
expression:
<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.
<h:commandButton value="Login" action="welcome"/>
The desired next page is dependent on the state of a bean.
There are multiple command buttons and each needs to modify the state of a bean in a different way before navigating to the next page.
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";
}