5.2. <a4j:param>
The
<a4j:param> behavior combines the functionality of the JavaServer Faces (JSF) components <f:param> and <f:actionListener>.
5.2.1. Basic usage
Basic usage of the
<a4j:param> requires three main attributes:
- The
valueattribute is the initial value of the parameter. - The
assignToattribute defines the bean property. The property is updated if the parent command component performs an action event during the Process Request phase.
Example 5.2, “
<a4j:param> example” shows a simple implementation along with the accompanying managed bean.
Example 5.2. <a4j:param> example
<h:form id="form"> <a4j:commandButton value="Set name to Alex" reRender="rep"> <a4j:param name="username" value="Alex" assignTo="#{paramBean.name}"/> </a4j:commandButton> <h:outputText id="rep" value="Name: #{paramBean.name}"/> </h:form>
public class ParamBean { private String name = "John"; public String getName() { return name; } public void setName(String name) { this.name = name; } }
When the button is pressed, the application sets the
name parameter of the bean to Alex, and displays the name in the output field.
5.2.2. Interoperability
The
<a4j:param> tag can be used with non-Ajax components in addition to Ajax components. This includes components which are working through the GET request, such as the <h:link> and <h:button> components. In this way, data model values can also be updated without any Java code on the server side.
The
converter attribute can be used to specify how to convert the value before it is submitted to the data model. The property is assigned the new value during the Update Model phase.
Note
If the validation of the form fails, the Update Model phase will be skipped and the property will not be updated.
5.2.3. Passing client-side parameters
Variables from JavaScript functions can be used for the
value attribute. In such an implementation, the noEscape attribute should be set to true. Using noEscape="true", the value attribute can contain any JavaScript expression or JavaScript function invocation, and the result will be sent to the server as the value attribute.
Example 5.3. Passing client-side parameters
<h:form> <a4j:commandButton value="Show Screen Size" render="infoPanel"> <a4j:param name="w" value="screen.width" assignTo="#{paramBean.screenWidth}" noEscape="true" /> <a4j:param name="h" value="screen.height" assignTo="#{paramBean.screenHeight}" noEscape="true" /> </a4j:commandButton> <h:panelGrid columns="2" id="infoPanel"> <h:outputText value="Width:" /> <h:outputText value="#{paramBean.screenWidth}" /> <h:outputText value="Height:" /> <h:outputText value="#{paramBean.screenHeight}" /> </h:panelGrid> </h:form>
The command button triggers the
<a4j:param> behaviors and renders the output text. The <a4j:param> behaviors pass client-side parameters for the screen width and height through the backing bean. These parameters are then used to populate the output text values.
5.2.4. Reference data
component-type:org.richfaces.Parametercomponent-class:org.richfaces.component.UIParametercomponent-family:javax.faces.Parameterhandler-class:org.richfaces.view.facelets.html.ParameterHandler