It combines the RichFaces functionalities of the JavaServer Faces ( JSF) components <f:param> and <f:actionListener>. It can be used with non-Ajax components in addition to Ajax components. It includes components such as the <h:link> and <h:button> components.
The RichFaces<a4j:param> requires the following attributes.
- The value attribute is the initial value of the parameter.
- The assignTo attribute defines the bean property. The property is updated if the parent command component performs an action event during the Process Request phase.
Example
Here, in the following example, we are implementing <a4j:param> component. This example contains the following files.
JSF File
// ajax-param.xhtml
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:a4j="http://richfaces.org/a4j"> <h:head> <title>Ajax Log</title> </h:head> <h:body> <h:form id="form"> <a4j:commandButton value="Set param" render="rep"> <a4j:param name="username" value="adglob" assignTo="#{ajaxParam.name}"/> </a4j:commandButton><br/><br/> <h:outputText id="rep" value="Hello #{ajaxParam.name}"/> </h:form> </h:body> </html>
Managed Bean
// User.java
import javax.faces.bean.ManagedBean; import javax.faces.bean.RequestScoped; @ManagedBean @RequestScoped public class User { String name; public String getName() { return name; } public void setName(String name) { this.name = name; } }