You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by gc...@apache.org on 2010/12/03 02:11:46 UTC
svn commit: r1041665 - in /myfaces/trinidad/trunk/trinidad-impl/src/main:
java/org/apache/myfaces/trinidadinternal/validator/DateTimeRangeValidator.java
javascript/META-INF/adf/jsLibs/CoreFormat.js
Author: gcrawford
Date: Fri Dec 3 01:11:46 2010
New Revision: 1041665
URL: http://svn.apache.org/viewvc?rev=1041665&view=rev
Log:
TRINIDAD-1967 DateTimeRangeValidator gives false failure if server specifies timezone attribute or timezone specified in trinidad-config.xml
Thanks to Yee-Wah
Modified:
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/DateTimeRangeValidator.java
myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/DateTimeRangeValidator.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/DateTimeRangeValidator.java?rev=1041665&r1=1041664&r2=1041665&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/DateTimeRangeValidator.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/DateTimeRangeValidator.java Fri Dec 3 01:11:46 2010
@@ -28,12 +28,15 @@ import java.util.Date;
import java.util.HashMap;
import java.util.Map;
+import java.util.TimeZone;
+
import javax.faces.component.UIComponent;
import javax.faces.component.EditableValueHolder;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.validator.ValidatorException;
+import org.apache.myfaces.trinidad.context.RequestContext;
import org.apache.myfaces.trinidad.logging.TrinidadLogger;
import org.apache.myfaces.trinidad.validator.ClientValidator;
import org.apache.myfaces.trinidadinternal.convert.DateTimeConverter;
@@ -126,8 +129,10 @@ public class DateTimeRangeValidator exte
// Trinidad-1818: Send min/max in two formats: one parseable by the converter (for hints),
// one in an ISO-like format that doesn't lose information if the converter has
// a pattern that loses information.
- String maxISOStr = (max == null) ? "null" : "'" + _ISO_FORMAT.format(max) + "'" ;
- String minISOStr = (min == null) ? "null" : "'" + _ISO_FORMAT.format(min) + "'" ;
+ // Trinidad-1967: Ensure the isoFormat uses the same timezone as the converter
+ SimpleDateFormat isoFormat = _getISOFormat (conv);
+ String maxISOStr = (max == null) ? "null" : "'" + isoFormat.format(max) + "'" ;
+ String minISOStr = (min == null) ? "null" : "'" + isoFormat.format(min) + "'" ;
return _getTrDateTimeRangeValidator(context, component, maxStr, maxISOStr,
minStr, minISOStr, cMessages);
}
@@ -176,13 +181,45 @@ public class DateTimeRangeValidator exte
outBuffer.append(')');
return outBuffer.toString();
}
-
+
+ private SimpleDateFormat _getISOFormat (Converter conv)
+ {
+ SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ // Trinidad-1967: ISOFormat should use the same timezone as the converter's
+ // Make sure this matches DateTimeConverter's#_getTimeZone
+ TimeZone tZone = null;
+
+ if (conv instanceof javax.faces.convert.DateTimeConverter)
+ tZone = ((javax.faces.convert.DateTimeConverter)conv).getTimeZone();
+
+ if (tZone == null)
+ {
+ RequestContext context = RequestContext.getCurrentInstance();
+ if (context == null)
+ {
+ _LOG.warning("NO_REQUESTCONTEXT_TIMEZONE_DEFAULT");
+ }
+ else
+ {
+ tZone = context.getTimeZone();
+ }
+
+ // If RequestContext is null or if it returns a null,
+ // then set it to the default time zone which is GMT time zone
+ if (tZone == null)
+ {
+ tZone = _DEFAULT_TIME_ZONE;
+ }
+ }
+ isoFormat.setTimeZone(tZone);
+ return isoFormat;
+ }
private static final TrinidadLogger _LOG = TrinidadLogger
.createTrinidadLogger(DateTimeRangeValidator.class);
private static final Collection<String> _IMPORT_NAMES = Collections.singletonList( "TrNumberConverter()" );
- private static final SimpleDateFormat _ISO_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ private static final TimeZone _DEFAULT_TIME_ZONE = TimeZone.getTimeZone("GMT");
}
Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js?rev=1041665&r1=1041664&r2=1041665&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js Fri Dec 3 01:11:46 2010
@@ -635,12 +635,12 @@ TrDateTimeRangeValidator.prototype.valid
// If so, revert to previous behavior where we just parse the min/maxValue string, though
// that may have less information than the ISO version.
minDate = (this._minISODate == null) ?
- converter.getAsObject (this._minValue):
- isoConverter.getAsObject (this._minISODate);
+ converter.getAsObject (this._minValue).getTime() :
+ isoConverter.getAsObject (this._minISODate).getTime ();
maxDate = (this._maxISODate == null) ?
- converter.getAsObject (this._maxValue):
- isoConverter.getAsObject (this._maxISODate);
+ converter.getAsObject (this._maxValue).getTime () :
+ isoConverter.getAsObject (this._maxISODate).getTime ();
}
catch (e)
{
@@ -683,8 +683,8 @@ TrDateTimeRangeValidator.prototype.valid
try
{
minDate = (this._minISODate == null) ?
- converter.getAsObject (this._minValue):
- isoConverter.getAsObject (this._minISODate);
+ converter.getAsObject (this._minValue).getTime ():
+ isoConverter.getAsObject (this._minISODate).getTime ();
}
catch (e)
{
@@ -723,8 +723,8 @@ TrDateTimeRangeValidator.prototype.valid
try
{
maxDate = (this._maxISODate == null) ?
- converter.getAsObject (this._maxValue):
- isoConverter.getAsObject (this._maxISODate);
+ converter.getAsObject (this._maxValue).getTime ():
+ isoConverter.getAsObject (this._maxISODate).getTime ();
}
catch (e)
{