Binding the Form Elements With the Bean Properties

This example illustrates how to bind the value of the component to the property of the bean or to refer method of the bean from component tag

Binding the Form Elements With the Bean Properties

This example illustrates how to bind the value of the component to the property of the bean or to
refer method of the bean from component tag, Expression Language (EL) "#{
}" syntax is used for this purpose. For example, #{BeanName.propertyName}
can be
used to bind the value of the component to the property "propertyName"
of the bean "BeanName". #{BeanName.methodName} can be
used to refer method "methodName()" of the bean "BeanName",
when button is clicked. When page is rendered, the values for the
components are accessed using getter methods of the related properties and when
the form is submitted by clicking on button the appropriate setter methods are
called to set the values to the beans properties and the method methodName() is
called on button click.

In this source code we have associated values of the UIcomponents to
the backing bean's properties. The bean's properties loginid and
password are bound to the input components. When the user fills values in these components
and submit the form, these values are stored in the
properties of the bean. So when they are again bound with the component, stored
values are used. For example, in "success.jsp" page we have
again used these properties values so it considers the values filled in previous
page. Command button component's action is associated with CheckValidUser()
method of the Bean class. This method returns a String value either "success"
or "fail". This value is set to the action attribute of
the commandButton tag. This button works according to the returned value
and the navigation rules specified in the "faces-config.xml"
file.