JSF Showcase
f:viewAction
Since JSF 2.2, you can invoke anaction
or actionListener
, passing through the JSF phases using f:viewAction.
General Usage
It's possible to choose this method to be executed during non-JSF request (GET) or in a postBack, usingpostBack
attribute. Another useful attribute could be phase
, as there you can specify which JSF PhaseId you want that method to be invoked on.
View action was executed in phase UPDATE_MODEL_VALUES 4
Source Code
- <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://xmlns.jcp.org/jsf/core"
- xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
- <f:metadata>
- <f:viewAction action="#{viewMetadataBackingBean.viewAction}" phase="UPDATE_MODEL_VALUES"/>
- </f:metadata>
- <h:outputText value="#{viewMetadataBackingBean.viewActionText}"/>
- </ui:composition>
- @ManagedBean
- @RequestScoped
- public class ViewMetadataBackingBean {
- private String viewActionText;
- private Country viewCountry;
- public String getViewActionText() {
- return viewActionText;
- }
- public Country getViewCountry() {
- return viewCountry;
- }
- public void setViewActionText(String viewActionText) {
- this.viewActionText = viewActionText;
- }
- public void setViewCountry(Country viewCountry) {
- this.viewCountry = viewCountry;
- }
- public String viewAction() {
- PhaseId phaseId = FacesContext.getCurrentInstance().getCurrentPhaseId();
- String phaseName = phaseId.toString();
- this.viewActionText = "View action was executed in phase " + phaseName;
- return null;
- }
- }
Liferay Faces Bridge Implementation 5.0.0 + Showcase Common 3.1.1 + Liferay Faces Util 3.4.1 + Mojarra 2.2.20