The Java EE 5 Tutorial

Developing the Beans

Developing beans is one responsibility of the application developer. A typical JavaServer Faces application couples a backing bean with each page in the application. The backing bean defines properties and methods that are associated with the UI components used on the page.

The page author binds a component’s value to a bean property using the component tag’s value attribute to refer to the property. Recall that the userNo component on the greeting.jsp page references the userNumber property of UserNumberBean:

<h:inputText id="userNo" label="User Number"

Here is the userNumber backing bean property that maps to the data for the userNo component:

Integer userNumber = null;
public void setUserNumber(Integer user_number) {
    userNumber = user_number;
public Integer getUserNumber() {
    return userNumber;
public String getResponse() {
    if(userNumber != null &&
         userNumber.compareTo(randomInt) == 0) {
            return "Yay! You got it!";
    } else {
        return "Sorry, "+userNumber+" is incorrect.";

See Backing Beans for more information on creating backing beans.