I am trying to register different converter instances in the faces-config, using a standard converter class to which different parameters are passed.
The code below registers two DateTimeConverters, the first one for dates including time and the second one for time only. But the pattern property never gets set. Can this be done?
<converter>
<converter-id>dateTimeConverter</converter-id>
<converter-class>javax.faces.convert.DateTimeConverter</converter-class>
<property>
<property-name>pattern</property-name>
<suggested-value>yyyy-MM-dd HH:mm:ss</suggested-value>
</property>
</converter>
<converter>
<converter-id>timeConverter</converter-id>
<converter-class>javax.faces.convert.DateTimeConverter</converter-class>
<property>
<property-name>pattern</property-name>
<suggested-value>HH:mm:ss</suggested-value>
</property>
</converter>
This is unfortunately not possible through
faces-config.xml. The<property>declaration which you’re trying is not used during runtime.If all you want is to control the pattern at one place, then best what you can do is to create a custom converter. For this particular purpose it isn’t that hard. Just extend
DateTimeConverterand set the pattern during construction. Here’s a basic example:You can of course get the pattern from somewhere else, e.g. a properties file or xml file in classpath.
Register this converter as follows:
That should be it. No need for
f:converterorUIOutput#setConverterId().