incubator-adffaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mat...@apache.org
Subject svn commit: r488660 - in /incubator/adffaces/trunk/trinidad/trinidad-impl/src/main: java/org/apache/myfaces/trinidadinternal/validator/DateTimeRangeValidator.java javascript/META-INF/adf/jsLibs/CoreFormat.js
Date Tue, 19 Dec 2006 12:41:57 GMT
Author: matzew
Date: Tue Dec 19 04:41:56 2006
New Revision: 488660

URL: http://svn.apache.org/viewvc?view=rev&rev=488660
Log:
enhanced timerangevalidator to send down custom messages

Modified:
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/DateTimeRangeValidator.java
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/DateTimeRangeValidator.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/DateTimeRangeValidator.java?view=diff&rev=488660&r1=488659&r2=488660
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/DateTimeRangeValidator.java
(original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/DateTimeRangeValidator.java
Tue Dec 19 04:41:56 2006
@@ -14,9 +14,12 @@
 * limitations under the License.
 */
 package org.apache.myfaces.trinidadinternal.validator;
+import java.io.IOException;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
 
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
@@ -24,6 +27,7 @@
 
 import org.apache.myfaces.trinidad.validator.ClientValidator;
 import org.apache.myfaces.trinidadinternal.convert.GenericConverterFactory;
+import org.apache.myfaces.trinidadinternal.util.JsonUtils;
 
 public class DateTimeRangeValidator extends org.apache.myfaces.trinidad.validator.DateTimeRangeValidator
                                        implements ClientValidator
@@ -73,10 +77,24 @@
   {
     Date max = getMaximum();
     Date min = getMinimum();
-    String maxStr = (max == null) ? null : Long.toString(max.getTime());
-    String minStr = (min == null) ? null : Long.toString(min.getTime());
+    String maxStr = (max == null) ? "null" : Long.toString(max.getTime());
+    String minStr = (min == null) ? "null" : Long.toString(min.getTime());
     
-    return _getTrDateTimeRangeValidator(context, component, maxStr, minStr);
+    String messageDetailMax = this.getMessageDetailMaximum();
+    String messageDetailMin = this.getMessageDetailMinimum();
+    String messageDetailRange = this.getMessageDetailNotInRange();
+    
+    Map<String, String> cMessages = null;
+    if(messageDetailMax != null || messageDetailMin != null || messageDetailRange != null)
+    {
+      cMessages = new HashMap<String, String>();
+      cMessages.put("max", messageDetailMax);
+      cMessages.put("min", messageDetailMin);
+      cMessages.put("range", messageDetailRange);
+    }
+
+    
+    return _getTrDateTimeRangeValidator(context, component, maxStr, minStr, cMessages);
     
   }
   
@@ -91,14 +109,31 @@
       FacesContext context,
       UIComponent component,
       String max,
-      String min)
+      String min,
+      Map messages)
   {
     StringBuilder outBuffer = new StringBuilder(31 + min.length() + max.length());
     outBuffer.append("new TrDateTimeRangeValidator(");
     outBuffer.append(max);
     outBuffer.append(',');
     outBuffer.append(min);
-    outBuffer.append(")");
+    outBuffer.append(',');
+    if(messages == null)
+    {
+      outBuffer.append("null");
+    }
+    else
+    {
+      try
+      {
+        JsonUtils.writeMap(outBuffer, messages, false);
+      }
+      catch (IOException e)
+      {
+        outBuffer.append("null");
+      }
+    }
+    outBuffer.append(')');
 
     return outBuffer.toString();
   }

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js?view=diff&rev=488660&r1=488659&r2=488660
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js
(original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js
Tue Dec 19 04:41:56 2006
@@ -346,7 +346,6 @@
   string = "" + value;
   numberValue = parseFloat(string);
   var facesMessage;
-  
   if(this._minValue && this._maxValue)
   {
   	//range
@@ -525,12 +524,12 @@
 
 function TrDateTimeRangeValidator(
   maxValue,
-  minValue)
+  minValue,
+  messages)
 {
- 
   this._maxValue = maxValue;
   this._minValue = minValue;
-
+  this._messages = messages;
   // for debugging
   this._class = "TrDateTimeRangeValidator";
 }
@@ -554,23 +553,98 @@
 )
 {
   dateTime = value.getTime();
-  minDate = parseInt(this._minValue);
-  maxDate = parseInt(this._maxValue);
-  
-  if(dateTime >= minDate && dateTime <= maxDate)
+  var facesMessage;
+  //range
+  if(this._minValue && this._maxValue)
   {
-    return value;
+    minDate = parseInt(this._minValue);
+    maxDate = parseInt(this._maxValue);
+    if(dateTime >= minDate && dateTime <= maxDate)
+    {
+      return value;
+    }
+    else
+    {
+    	var key = "org.apache.myfaces.trinidad.validator.DateTimeRangeValidator.NOT_IN_RANGE";
+    	if(this._messages && this._messages["range"])
+        {
+          facesMessage = _createCustomFacesMessage(TrMessageFactory.getSummaryString(key),
+                                        this._messages["range"],
+                                        label,
+                                        ""+converter.getAsString(value),
+                                        ""+converter.getAsString(new Date(this._minValue)),
+                                        ""+converter.getAsString(new Date(this._maxValue)));
+        }
+    	else
+    	{
+          facesMessage = _createFacesMessage(key,
+                                        label,
+                                        string,
+                                        ""+this._minValue,
+                                        ""+this._maxValue);
+    	}
+    }
   }
   else
   {
-    facesMessage = _createFacesMessage("org.apache.myfaces.trinidad.validator.DateTimeRangeValidator.NOT_IN_RANGE",
+    //only min
+    if(this._minValue)
+    {
+      minDate = parseInt(this._minValue);
+      if(dateTime >= minDate)
+      {
+        return value;
+      }
+      else
+      {
+        var key = "org.apache.myfaces.trinidad.validator.DateTimeRangeValidator.MINIMUM";
+    	if(this._messages && this._messages["min"])
+        {
+          facesMessage = _createCustomFacesMessage(TrMessageFactory.getSummaryString(key),
+                                        this._messages["min"],
+                                        label,
+                                        ""+converter.getAsString(value),
+                                        ""+converter.getAsString(new Date(this._minValue)));
+        }
+    	else
+    	{
+          facesMessage = _createFacesMessage(key,
+                                        label,
+                                        ""+converter.getAsString(value),
+                                        ""+converter.getAsString(new Date(this._minValue)));
+    	}
+      }
+    }
+    //max only
+    else
+    {
+      maxDate = parseInt(this._maxValue);
+      if(dateTime <= maxDate)
+      {
+        return value;
+      }
+      else
+      {
+        var key = "org.apache.myfaces.trinidad.validator.DateTimeRangeValidator.MAXIMUM";
+    	if(this._messages && this._messages["max"])
+        {
+          facesMessage = _createCustomFacesMessage(TrMessageFactory.getSummaryString(key),
+                                        this._messages["max"],
+                                        label,
+                                        ""+converter.getAsString(value),
+                                        ""+converter.getAsString(new Date(this._maxValue)));
+        }
+    	else
+    	{
+          facesMessage = _createFacesMessage(key,
                                         label,
                                         ""+converter.getAsString(value),
-                                        ""+converter.getAsString(new Date(this._minValue)),
                                         ""+converter.getAsString(new Date(this._maxValue)));
-    throw new TrConverterException(facesMessage);
+    	}
+      }
+    }
   }
-  
+  throw new TrConverterException(facesMessage);
 }
 
 function TrDateRestrictionValidator(



Mime
View raw message