A simple JSF-AJAX example to get started

The simplest JSF-AJAX example can be written in a matter of a few seconds. Let's consider a JSF form with an input text and a button that sends the user input to the server. The user input (a string) is converted by the server to uppercase and is displayed to the user in an output text component. Next, you can ajaxify this scenario as shown in the following example code:

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

The presence of the <f:ajax> tag is sufficient to transform this request into an AJAX request. Well, it is true ...

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.