You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ar...@apache.org on 2010/10/16 00:09:16 UTC

svn commit: r1023132 - 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: arobinson74
Date: Fri Oct 15 22:09:16 2010
New Revision: 1023132

URL: http://svn.apache.org/viewvc?rev=1023132&view=rev
Log:
TRINIDAD-1920 commit patch to 1.2.12.3 branch

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=1023132&r1=1023131&r2=1023132&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 Fri Oct 15 22:09:16 2010
@@ -19,6 +19,9 @@
 package org.apache.myfaces.trinidadinternal.validator;
 
 import java.io.IOException;
+
+import java.text.SimpleDateFormat;
+
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
@@ -108,8 +111,8 @@ public class DateTimeRangeValidator exte
     String hintRange = this.getHintNotInRange();
     
     Map<String, String> cMessages = null;
-    if (messageDetailMax != null || messageDetailMin != null || messageDetailRange != null || 
-        hintMax != null || hintMin != null || hintRange != null)
+    if(messageDetailMax != null || messageDetailMin != null || messageDetailRange != null || 
+       hintMax != null || hintMin != null|| hintRange != null)
     {
       cMessages = new HashMap<String, String>();
       cMessages.put("max", messageDetailMax);
@@ -120,10 +123,13 @@ public class DateTimeRangeValidator exte
       cMessages.put("hintRange", hintRange);
     }
     
-    return _getTrDateTimeRangeValidator(context, component, maxStr, minStr, 
-                                        max != null ? Long.toString(max.getTime()) : "null", 
-                                        min != null ? Long.toString(min.getTime()) : "null", 
-                                        cMessages);
+    // 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) + "'" ;
+    return _getTrDateTimeRangeValidator(context, component, maxStr, maxISOStr, 
+                                        minStr, minISOStr, cMessages);
   }
   
   public String getClientLibrarySource(
@@ -136,9 +142,9 @@ public class DateTimeRangeValidator exte
       FacesContext context,
       UIComponent component,
       String max,
+      String maxISOStr,
       String min,
-      String maxMilli,
-      String minMilli,
+      String minISOStr,
       Map<String, String> messages)
   {
     StringBuilder outBuffer = new StringBuilder(31 + min.length() + max.length());
@@ -162,12 +168,11 @@ public class DateTimeRangeValidator exte
         outBuffer.append("null");
       }
     }
+    outBuffer.append(maxISOStr);
     outBuffer.append(',');
-    outBuffer.append(maxMilli);
+    outBuffer.append(minISOStr);
     outBuffer.append(',');
-    outBuffer.append(minMilli);
     outBuffer.append(')');
-
     return outBuffer.toString();
   }
 
@@ -175,6 +180,8 @@ public class DateTimeRangeValidator exte
   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");
   
   
 }

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=1023132&r1=1023131&r2=1023132&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 Fri Oct 15 22:09:16 2010
@@ -567,18 +567,24 @@ TrLengthValidator.prototype.validate  = 
   }
 }
 
+// Trinidad-1818: When min/max is specified, use two pieces of information
+// min/maxValue         : The date as a string parseable by the converter (for hints)
+// minISODate/maxISODate: The date as an ISO-like string to correctly recreate the Date object.
+//                        This is because the converter pattern could lose information, e.g. with a
+//                        Date of 4712-12-31 and converter with YY, min/maxValue would be "12-12-31"
+//                        and the converter would parse that into 2012-12-31. See Trinidad-1920
 function TrDateTimeRangeValidator(
-  maxDateString,
-  minDateString,
+  maxValue,
+  minValue,
   messages,
-  maxDateMilliseconds,
-  minDateMilliseconds
+  maxISODate,
+  minISODate  
   )
 {
-  this._maxDateString = maxDateString;
-  this._minDateString = minDateString;
-  this._maxDateMilliseconds = maxDateMilliseconds;
-  this._minDateMilliseconds = minDateMilliseconds;
+  this._maxValue = maxValue;
+  this._maxISODate = maxISODate;
+  this._minValue = minValue;
+  this._minISODate = minISODate;
   this._messages = messages;
   // for debugging
   this._class = "TrDateTimeRangeValidator";
@@ -589,9 +595,15 @@ TrDateTimeRangeValidator.prototype.getHi
   converter
   )
 {
-  var max = this._maxDateString ? this._maxDateString : null;
-  var min = this._minDateString ? this._minDateString : null;
+ var max = null;
+ var min = null;
 
+  if (this._maxValue)
+    max = this._maxValue;
+
+  if (this._minValue)
+    min = this._minValue;
+    
   return _returnRangeHints(
     this._messages,
     max,
@@ -605,6 +617,14 @@ TrDateTimeRangeValidator.prototype.getHi
   );
 }
 
+TrDateTimeRangeValidator.prototype.getISOConverter = function ()
+{
+  // This pattern must be kept in sync with DateTimeRangeValidator#_ISO_FORMAT
+ if (this._ISO_CONVERTER == null)
+   this._ISO_CONVERTER = new TrDateTimeConverter("yyyy-MM-dd HH:mm:ss",  null, null, null, null);
+ return this._ISO_CONVERTER;
+}
+
 TrDateTimeRangeValidator.prototype.validate  = function(
   value,
   label,
@@ -613,16 +633,23 @@ TrDateTimeRangeValidator.prototype.valid
 {
   dateTime = value.getTime();
   var facesMessage;
-  //range
-  if (this._minDateString && this._maxDateString)
+  var isoConverter = this.getISOConverter ();
+ 
+ //range
+  if (this._minValue && this._maxValue)
   {
     try
     {
-      minDate = (this._minDateMilliseconds != null) ? this._minDateMilliseconds : 
-        converter.getAsObject(this._minDateString).getTime();
-        
-      maxDate = (this._maxDateMilliseconds != null) ? this._maxDateMilliseconds : 
-        converter.getAsObject(this._maxDateString).getTime();
+       // min/maxISODate were introduced in TRINIDAD-1920, pre-existing callers may have them null.
+       // 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);
+
+        maxDate = (this._maxISODate == null) ? 
+                    converter.getAsObject (this._maxValue):
+                    isoConverter.getAsObject (this._maxISODate);
     }
     catch (e)
     {
@@ -644,28 +671,29 @@ TrDateTimeRangeValidator.prototype.valid
                                         this._messages["range"],
                                         label,
                                         ""+converter.getAsString(value),
-                                        ""+this._minDateString,
-                                        ""+this._maxDateString);
+                                        ""+this._minValue,
+                                        ""+this._maxValue);
       }
       else
       {
           facesMessage = _createFacesMessage(key,
                                         label,
                                         ""+converter.getAsString(value),
-                                        ""+this._minDateString,
-                                        ""+this._maxDateString);
+                                        ""+this._minValue,
+                                        ""+this._maxValue);
       }
     }
   }
   else
   {
     //only min
-    if (this._minDateString)
+    if (this._minValue)
     {
       try
       {
-        minDate = (this._minDateMilliseconds != null) ? this._minDateMilliseconds : 
-          converter.getAsObject(this._minDateString).getTime();
+        minDate = (this._minISODate == null) ? 
+                    converter.getAsObject (this._minValue):
+                    isoConverter.getAsObject (this._minISODate);
       }
       catch (e)
       {
@@ -687,24 +715,25 @@ TrDateTimeRangeValidator.prototype.valid
                                         this._messages["min"],
                                         label,
                                         ""+converter.getAsString(value),
-                                        ""+this._minDateString);
+                                        ""+this._minValue);
         }
         else
         {
           facesMessage = _createFacesMessage(key,
                                         label,
                                         ""+converter.getAsString(value),
-                                        ""+this._minDateString);
+                                        ""+this._minValue);
         }
       }
     }
     //max only
-    else if (this._maxDateString)
+    else if (this._maxValue)
     {
       try
       {
-        maxDate = (this._maxDateMilliseconds != null) ? this._maxDateMilliseconds : 
-          converter.getAsObject(this._maxDateString).getTime();
+        maxDate = (this._maxISODate == null) ? 
+                    converter.getAsObject (this._maxValue):
+                    isoConverter.getAsObject (this._maxISODate);
       }
       catch (e)
       {
@@ -726,14 +755,14 @@ TrDateTimeRangeValidator.prototype.valid
                                         this._messages["max"],
                                         label,
                                         ""+converter.getAsString(value),
-                                        ""+this._maxDateString);
+                                        ""+this._maxValue);
         }
         else
         {
           facesMessage = _createFacesMessage(key,
                                         label,
                                         ""+converter.getAsString(value),
-                                        ""+this._maxDateString);
+                                        ""+this._maxValue);
         }
       }
     }