<h:commandButton> is used to submit a form to the server. The value of its value
attribute is used to generate the text of the rendered button. The value of its action
attribute is used to determine what page to display after the button is pressed.
In our example, we are using static navigation . When using JSF static navigation,
the value of the action attribute of a command button is hard-coded in the markup.
When using static navigation, the value of the action attribute of
<h:commandButton> corresponds to the name of the page we want to navigate to,
minus its .xhtml extension. In our example, when the user clicks on the button, we
want to navigate to a file named confirmation.xhtml , therefore we used a value of
"confirmation" for its action attribute.
An alternative to static navigation is dynamic navigation . When using dynamic
navigation, the value of the action attribute of the command button is a value
binding expression resolving to a method returning a String in a managed
bean. The method may then return different values based on certain conditions.
Navigation would then proceed to a different page depending on the value of the
As long as it returns a String , the managed bean method executed when using
dynamic navigation can contain any logic inside it, and is frequently used to save
data in a managed bean into a database.
When using dynamic navigation, the return value of the method executed when
clicking the button must match the name of the page we want to navigate to (again,
minus the file extension).
In earlier versions of JSF, it was necessary to specify navigation rules in faces-
config.xml , with the introduction of the conventions introduced in the previous
paragraphs, this is no longer necessary.