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/04 02:03:39 UTC

svn commit: r1042080 - in /myfaces/trinidad/branches/1.2.12.3-branch/trinidad-impl/src/main: java/org/apache/myfaces/trinidadinternal/validator/DateTimeRangeValidator.java javascript/META-INF/adf/jsLibs/CoreFormat.js

Author: gcrawford
Date: Sat Dec  4 01:03:39 2010
New Revision: 1042080

URL: http://svn.apache.org/viewvc?rev=1042080&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/branches/1.2.12.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/DateTimeRangeValidator.java
    myfaces/trinidad/branches/1.2.12.3-branch/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js

Modified: myfaces/trinidad/branches/1.2.12.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/DateTimeRangeValidator.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/DateTimeRangeValidator.java?rev=1042080&r1=1042079&r2=1042080&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/DateTimeRangeValidator.java (original)
+++ myfaces/trinidad/branches/1.2.12.3-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/DateTimeRangeValidator.java Sat Dec  4 01:03:39 2010
@@ -27,13 +27,14 @@ import java.util.Collections;
 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 +127,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);
   }
@@ -178,12 +181,45 @@ public class DateTimeRangeValidator exte
     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/branches/1.2.12.3-branch/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.3-branch/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js?rev=1042080&r1=1042079&r2=1042080&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.3-branch/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js (original)
+++ myfaces/trinidad/branches/1.2.12.3-branch/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js Sat Dec  4 01:03:39 2010
@@ -644,12 +644,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)
     {
@@ -692,8 +692,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)
       {
@@ -732,8 +732,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)
       {