f:converter |
|
The Converter tag registers a Converter instance on the component associated with the enclosing tag. It takes one attribute: the converterId that you used to register your converter in your Faces configuration file.
The Converter interface is implemented by classes that handle custom conversion of user input into a data type expected by the domain model of your JSF application, and vice versa. For example, you might have a select list of countries that your user can choose from.
You could create a custom converter to handle converting the underlying Country objects in your list into strings to display to the user. When the user submits the form, your converter would also handle converting the selected country ID into the appropriate Country object expected by your domain model.
Example:
<h:selectOneMenu value="#{customerBean.customer.address.country}">
<f:converter converterId="countryConverter"></f:converter>
<f:selectItems value="#{locationBean.countryList}"></f:selectItems>
</h:selectOneMenu>
HTML Output
<select>
<option value="1">Canada</option>
<option value="2">USA</option>
...
</select>
|