JSF Showcase

f:setPropertyActionListener

f:setPropertyActionListener makes it easier to do a common task in JSF application development: set a value when executing an UICommand.

General Usage

To set the target UIComponent implementing ActionSource, use for attribute (this can be avoided if nested to another UICommand Facelet element). For specifying the bean value to be set, use target attribute, and use value for getting the same that will be used into target. This Facelet will then add a new dynamic ActionListener to the parent component (or the one set in forattribute). This ActionListener will set the target value obtained from value expression.

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">

	<h:form>
		<h:commandButton value="#{i18n['submit']}">
			<f:setPropertyActionListener target="#{setPropertyActionListenerBackingBean.targetText}" 
			value="Source Text"/>
			<f:ajax execute="@form" render="@form"/>
		</h:commandButton>											
		<h:outputText value="#{setPropertyActionListenerBackingBean.targetText}"/>
	</h:form>

</ui:composition>
@ManagedBean
@RequestScoped
public class SetPropertyActionListenerBackingBean {

	private String targetText;

	public String getTargetText() {
		return targetText;
	}

	public void setTargetText(String targetText) {
		this.targetText = targetText;
	}

}
Liferay Faces Bridge Implementation 4.1.0 + Showcase Common 3.0.1 + Liferay Faces Util 3.1.0 + Mojarra 2.2.14