Java Reference
In-Depth Information
<ui:composition template="../layout/custom_template.xhtml">
<ui:define name="content">
<f:viewAction action="#{viewActionManagedBean.viewActionExample()}"/>
Please look in the server log to see the message that is being
printed via the viewActionManagedBean.viewActionExample() method.
In the ViewActionManagedBean controller, the action method named viewActionExample is invoked using the
viewAction . In the following example method, a String is returned, which enables implicit navigation from the
action method. If null is returned, the navigation handler is invoked, but the same view will be rendered again so
long as there are no navigation condition expressions that change the navigation. If a String -based view name is
returned, then the navigation handler will render that view once the method has completed. This can come in handy
for situations such as authentication handling, where an action method is used to check the user's role, and then the
appropriate view is rendered based upon the authenticated user role.
public String viewActionExample(){
System.out.println("This is being written to the server log when the "
+ "view is accessed...");
return null;
As mentioned previously, the viewAction facet can be customized to allow the action method to be invoked at
different stages within the view life cycle. By default, the viewAction will be initiated before postback because they
are expected to execute whether the request was Faces or non-Faces. However, this can be changed by setting the
onPostback attribute of the viewAction tag to true .
<f:viewAction action="#{viewActionManagedBean.viewActionExample()}" onPostback="true"/>
If you need to get even more granular and invoke a view action during a specified life-cycle phase, it is
possible by setting the phase attribute to the phase required. Table 2-1 specifies the different phases along with
their phase value.
Table 2-1. JSF Life-Cycle Phases
Tag Value
Restore View
Apply Request Values
Process Validations
Update Model Values
Invoke Application
Render Response
Search WWH ::

Custom Search