I am using the following JSF converter for my date inputs.
<f:convertDateTime dateStyle="medium" timeZone="EST" type="date" />
I want to centralize the converter so that I can change the timezone or the datestyle in one place. How is that possible?
Can I override the <f:convertDateTime>?
The only way is relying on system default timezone (instead of UTC as internally used by JSF). So, if you have 100% control over the production runtime environment and the production system platform timezone is EST, then just add the following context parameter to
web.xml:This way JSF will use the system platform timezone as obtained by
TimeZone#getDefault()as converter’s default timezone instead of UTC.If you have no control over it, then your best bet is to create an application scoped bean holding that property and reference it instead:
You can extend the
DateTimeConverterclass behind<f:convertDateTime>as follows in order to get a converter with all properties already set, but you would not be able to declare additional attributes from the view side on without wrapping it in a custom tag (which requires aTagHandlerand some XML boilerplate):Use it as
<f:converter converterId="defaultDateConverter" />