AJAX and <f:param>

The <f:param> tag can be used to pass request parameters to a managed bean. Since we have discussed this tag in detail in Chapter 2, Communication in JSF, we can continue here with an example of using it inside <f:ajax>:

<h:form>
  <h:inputText id="nameInputId" value="#{ajaxBean.name}"/>
  <h:commandButton value="Send" action="#{ajaxBean.ajaxAction()}">
    <f:ajax execute ="nameInputId" render="nameOutputId">
      <f:param name="surnameInputId" value="Nadal"/>
    </f:ajax>
  </h:commandButton>
  <h:outputText id="nameOutputId" value="#{ajaxBean.name}"/>
</h:form>

Remember that the parameter that was passed is available in the request parameter map:

FacesContext fc = FacesContext.getCurrentInstance(); Map<String, String> params = fc.getExternalContext().getRequestParameterMap(); ...

Get Mastering JavaServer Faces 2.2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.