The following is a piece of sample code in JSF that uses converter:
<h:inputText id="date" value="#{payment.date}">
<f:convertDateTime pattern="MM/yyyy"/>
</h:inputText>
The convertDateTime converter is an independent object from the inputText tag handler class. Then
how does the inputText tag know to use the convertDateTime converter to process the date value?
The secret is in the component class.
We know the tag handler class has an API method
public String getComponentType() {...}
that tells its component class.
The component class has an API method
public String getRenderType(){...}
that tells the renderer class.
The renderer class has the API method
public Object getConvertedValue(FacesContext context,
UIComponent component,
Object submittedValue)
{...}
that converts the value. So it is the responsibility of the renderer class to convert the value.
For example, the standard component class UIInput uses the specified converter. If you need to
create a customer renderer, you will need to set the converter in the renderer.
No comments:
Post a Comment