Java Reference
In-Depth Information
• Bind the custom Validator implementation to a managed bean property using
the f:validator tag's binding attribute, as described in “ Binding Convert-
ers, Listeners, and Validators to Managed Bean Properties on page 138 .
The following tag registers a hypothetical validator on a component using a validator
tag and references the ID of the validator:
Click here to view code image
<h:inputText id="name" value="#{CustomerBean.name}"
size="10" ... >
<f:validator validatorId="customValidator" />
...
</h:inputText>
Binding Component Values and Instances to Managed Bean Properties
A component tag can wire its data to a managed bean by one of the following methods:
• Binding its component's value to a bean property
• Binding its component's instance to a bean property
To bind a component's value to a managed bean property, a component tag's value at-
tribute uses a EL value expression. To bind a component instance to a bean property, a
component tag's binding attribute uses a value expression.
When a component instance is bound to a managed bean property, the property holds the
component's local value. Conversely, when a component's value is bound to a managed
bean property, the property holds the value stored in the managed bean. This value is up-
dated with the local value during the Update Model Values phase of the lifecycle. There
are advantages to both of these methods.
Binding a component instance to a bean property has these advantages:
• The managed bean can programmatically modify component attributes.
• The managed bean can instantiate components rather than let the page author do
so.
Binding a component's value to a bean property has these advantages:
• The page author has more control over the component attributes.
• The managed bean has no dependencies on the JavaServer Faces API (such as the
component classes), allowing for greater separation of the presentation layer from
the model layer.
Search WWH ::




Custom Search