MyFaces Commons Converters contains some useful converters not provided by the spec, and a base class for create custom converters using myfaces-builder-plugin.
This base class (
org.apache.myfaces.commons.converter.ConverterBase ) allow use ValueExpressions and in 2.0 version provides an implementation of StateHelper. This is useful in cases where parameters for the converter are bound to ValueExpression instance that are evaluated at runtime. By default, converter parameters are evaluated on build time (the first time the view is built), so they cannot change over the time (further web postback requests).
To understand this, take a look at this example:
It is a
<h:selectOneMenu> that allows you to choose a type that is then read by a converter. This can't work with
<f:convertNumber>, because the ValueExpression on type is evaluated at build time. But in this case,
<mcc:convertNumber> evaluate them each time the conversion occur. Note the
<h:selectOneMenu> makes the value of the component be evaluated before the conversion over the input text.
Also, in this project you can found:
- <mcc:convertBoolean> : Simple true/false converter with alternate representations of true false (yes/no), (1/0), and (way/no way).
- <mcc:convertDateTime> : Simple convert that overrides the spec DateTimeConverter and uses TimeZone.getDefault() as the base timezone, rather than GMT. Convert date time using normal system timezone like it should. In JSF 2.0 a new param for enable this behavior for f:convertDateTime was created called javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE.
- <mcc:convertEnum> : Alternate enum converter.
- <mcc:convertNumber> : Converter which uses either the manually set destType or the value binding to determine the correct destination type to convert the number to This tag creates a number formatting converter and associates it with the nearest parent UIComponent. It uses either the manually set destType or the value binding to determine the correct destination type to convert the number to.