Book Image

Mastering JavaServer Faces 2.2

By : Anghel Leonard
Book Image

Mastering JavaServer Faces 2.2

By: Anghel Leonard

Overview of this book

Table of Contents (20 chapters)
Mastering JavaServer Faces 2.2
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
The JSF Life Cycle
Index

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 that this request is not very useful because we did not specify which components should be executed and what components should be re-rendered. But the good part is that you will not receive...