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
:
<context-param>
<param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name>
<param-value>true</param-value>
</context-param>
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:
<f:convertDateTime ... timeZone="#{app.timeZone}" />
You can extend the DateTimeConverter
class 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 a TagHandler
and some XML boilerplate):
@FacesConverter("defaultDateConverter")
public class DefaultDateConverter extends DateTimeConverter {
public DefaultDateConverter() {
setDateStyle("medium");
setType("date");
setTimeZone(TimeZone.getTimeZone("EST"));
}
}
Use it as <f:converter converterId="defaultDateConverter" />
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…