Skip to content

Commit

Permalink
Fixes Google Code issue 331, set date time converter default time zone
Browse files Browse the repository at this point in the history
if necessary.
  • Loading branch information
Bauke Scholtz committed Jul 21, 2014
1 parent 2cbb80a commit bf833e3
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/main/java/org/omnifaces/application/OmniApplication.java
Expand Up @@ -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;
Expand All @@ -45,6 +51,7 @@ public class OmniApplication extends ApplicationWrapper {
// Variables ------------------------------------------------------------------------------------------------------

private final Application wrapped;
private final TimeZone dateTimeConverterDefaultTimeZone;

// Constructors ---------------------------------------------------------------------------------------------------

Expand All @@ -54,6 +61,10 @@ public class OmniApplication extends ApplicationWrapper {
*/
public OmniApplication(Application wrapped) {
this.wrapped = wrapped;
dateTimeConverterDefaultTimeZone =
Boolean.valueOf(getInitParameter(DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE_PARAM_NAME))
? TimeZone.getDefault()
: null;
}

// Actions --------------------------------------------------------------------------------------------------------
Expand All @@ -70,6 +81,7 @@ public Converter createConverter(String converterId) {
Converter converter = ((ConverterProvider) provider).createConverter(getWrapped(), converterId);

if (converter != null) {
setDefaultPropertiesIfNecessary(converter);
return converter;
}
}
Expand All @@ -89,6 +101,7 @@ public Converter createConverter(Class<?> targetClass) {
Converter converter = ((ConverterProvider) provider).createConverter(getWrapped(), targetClass);

if (converter != null) {
setDefaultPropertiesIfNecessary(converter);
return converter;
}
}
Expand Down Expand Up @@ -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.