Java Reference
In-Depth Information
In our example, we are using static navigation. When using JSF static navigation,
the value of the action attribute of a command button is hardcoded in the markup.
With JSF 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 the value 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 and returning a string in a CDI named
bean. The method can return different values based on certain conditions.
Navigation would then proceed to a different page depending on the value
of the method.
As long as it returns a string, the CDI named bean method
executed when using dynamic navigation can contain any
logic inside it, and it is frequently used to save data 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 discussed in the previous paragraphs, this is no
longer necessary.
Creating our CDI named bean
CDI named beans are standard JavaBeans that are used to hold user-entered data in
JSF applications.
Since a CDI named bean is a standard Java class, we create one like we create any
other Java class: by right-clicking on the Source Packages folder in the Projects
window and going to New | Java Class... .
 
Search WWH ::




Custom Search