Permalink
Browse files

Fixes Google Code issue 331, set date time converter default time zone

if necessary.
  • Loading branch information...
BalusC committed Jul 21, 2014
1 parent 2cbb80a commit bf833e39e2c880a3b75caa68d090a140a13956c8
Showing with 21 additions and 0 deletions.
  1. +21 −0 src/main/java/org/omnifaces/application/OmniApplication.java
@@ -15,10 +15,16 @@
*/
package org.omnifaces.application;
import static javax.faces.convert.Converter.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE_PARAM_NAME;
import static org.omnifaces.util.Faces.getInitParameter;
import java.util.TimeZone;
import javax.faces.FacesException;
import javax.faces.application.Application;
import javax.faces.application.ApplicationWrapper;
import javax.faces.convert.Converter;
import javax.faces.convert.DateTimeConverter;
import javax.faces.validator.Validator;
import org.omnifaces.config.BeanManager;
@@ -45,6 +51,7 @@
// Variables ------------------------------------------------------------------------------------------------------
private final Application wrapped;
private final TimeZone dateTimeConverterDefaultTimeZone;
// Constructors ---------------------------------------------------------------------------------------------------
@@ -54,6 +61,10 @@
*/
public OmniApplication(Application wrapped) {
this.wrapped = wrapped;
dateTimeConverterDefaultTimeZone =
Boolean.valueOf(getInitParameter(DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE_PARAM_NAME))
? TimeZone.getDefault()
: null;
}
// Actions --------------------------------------------------------------------------------------------------------
@@ -70,6 +81,7 @@ public Converter createConverter(String converterId) {
Converter converter = ((ConverterProvider) provider).createConverter(getWrapped(), converterId);
if (converter != null) {
setDefaultPropertiesIfNecessary(converter);
return converter;
}
}
@@ -89,6 +101,7 @@ public Converter createConverter(Class<?> targetClass) {
Converter converter = ((ConverterProvider) provider).createConverter(getWrapped(), targetClass);
if (converter != null) {
setDefaultPropertiesIfNecessary(converter);
return converter;
}
}
@@ -120,4 +133,12 @@ public Application getWrapped() {
return wrapped;
}
// Helpers --------------------------------------------------------------------------------------------------------
private void setDefaultPropertiesIfNecessary(Converter converter) {
if (converter instanceof DateTimeConverter && dateTimeConverterDefaultTimeZone != null) {
((DateTimeConverter) converter).setTimeZone(dateTimeConverterDefaultTimeZone);
}
}
}

0 comments on commit bf833e3

Please sign in to comment.