incubator-adffaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mat...@apache.org
Subject svn commit: r488600 - in /incubator/adffaces/trunk/trinidad/trinidad-impl/src/main: java/org/apache/myfaces/trinidadinternal/validator/ javascript/META-INF/adf/jsLibs/
Date Tue, 19 Dec 2006 09:44:23 GMT
Author: matzew
Date: Tue Dec 19 01:44:23 2006
New Revision: 488600

URL: http://svn.apache.org/viewvc?view=rev&rev=488600
Log:
enhanced long/double range validator to send down customized messages to the client

Modified:
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/DoubleRangeValidator.java
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/LongRangeValidator.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/DoubleRangeValidator.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/DoubleRangeValidator.java?view=diff&rev=488600&r1=488599&r2=488600
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/DoubleRangeValidator.java
(original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/DoubleRangeValidator.java
Tue Dec 19 01:44:23 2006
@@ -16,13 +16,17 @@
 
 package org.apache.myfaces.trinidadinternal.validator;
 
+import java.io.IOException;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
 
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
 
 import org.apache.myfaces.trinidad.validator.ClientValidator;
+import org.apache.myfaces.trinidadinternal.util.JsonUtils;
 
 /**
  * <p>Implementation for <code>java.lang.Long</code> values.</p>
@@ -54,11 +58,25 @@
     FacesContext context,
     UIComponent component)
   {
+    double max = getMaximum();
+    double min = getMinimum();
+    String maxStr = max == Double.MAX_VALUE ? "null" : Double.toString(max);
+    String minStr = min == Double.MIN_VALUE ? "null" : Double.toString(min);
     
-    String maxStr = Double.toString(getMaximum());
-    String minStr = Double.toString(getMinimum());
+    String messageDetailMax = this.getMessageDetailMaximum();
+    String messageDetailMin = this.getMessageDetailMinimum();
+    String messageDetailRange = this.getMessageDetailNotInRange();
     
-    return  _getTrRangeValidator(context, component, maxStr, minStr);
+    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  _getTrRangeValidator(context, component, maxStr, minStr, cMessages);
   }
   
   
@@ -72,14 +90,31 @@
       FacesContext context,
       UIComponent component,
       String max,
-      String min)
+      String min,
+      Map messages)
   {
     StringBuilder outBuffer = new StringBuilder();
     outBuffer.append("new TrRangeValidator(");
     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/java/org/apache/myfaces/trinidadinternal/validator/LongRangeValidator.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/LongRangeValidator.java?view=diff&rev=488600&r1=488599&r2=488600
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/LongRangeValidator.java
(original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/LongRangeValidator.java
Tue Dec 19 01:44:23 2006
@@ -16,14 +16,18 @@
 
 package org.apache.myfaces.trinidadinternal.validator;
 
+import java.io.IOException;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
 
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
 
 import org.apache.myfaces.trinidad.util.IntegerUtils;
 import org.apache.myfaces.trinidad.validator.ClientValidator;
+import org.apache.myfaces.trinidadinternal.util.JsonUtils;
 
 /**
  * <p>Implementation for <code>java.lang.Long</code> values.</p>
@@ -55,10 +59,25 @@
     FacesContext context,
     UIComponent component)
   {
-    String maxStr = IntegerUtils.getString(getMaximum());
-    String minStr = IntegerUtils.getString(getMinimum());
+    long max = getMaximum();
+    long min = getMinimum();
+    String maxStr = max == Long.MAX_VALUE ? "null" : IntegerUtils.getString(max);
+    String minStr = min == Long.MIN_VALUE ? "null" : IntegerUtils.getString(min);
     
-    return _getTrRangeValidator(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 _getTrRangeValidator(context, component, maxStr, minStr, cMessages);
 
   }
   
@@ -72,13 +91,30 @@
       FacesContext context,
       UIComponent component,
       String max,
-      String min)
+      String min,
+      Map messages)
   {
     StringBuilder outBuffer = new StringBuilder();
     outBuffer.append("new TrRangeValidator(");
     outBuffer.append(max);
     outBuffer.append(',');
     outBuffer.append(min);
+    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=488600&r1=488599&r2=488600
==============================================================================
--- 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 01:44:23 2006
@@ -307,10 +307,12 @@
 
 function TrRangeValidator(
   maxValue,
-  minValue)
+  minValue,
+  messages)
 {
   this._maxValue = maxValue;
   this._minValue = minValue;
+  this._messages = messages;
 
   // for debugging
   this._class = "TrRangeValidator";
@@ -341,32 +343,97 @@
   converter
 )
 {
-	
   string = "" + value;
   numberValue = parseFloat(string);
+  var facesMessage;
   
-  if(numberValue >= this._minValue && numberValue <= this._maxValue)
+  if(this._minValue && this._maxValue)
   {
-    return string;
-  }
-  else
-  {
-    if(numberValue>this._maxValue)
+  	//range
+    if(numberValue >= this._minValue && numberValue <= this._maxValue)
+    {
+      return string;
+    }
+    else
     {
-      facesMessage = _createFacesMessage("org.apache.myfaces.trinidad.validator.LongRangeValidator.MAXIMUM",
+    	var key = "org.apache.myfaces.trinidad.validator.LongRangeValidator.NOT_IN_RANGE";
+    	if(this._messages && this._messages["range"])
+    	{
+        facesMessage = _createCustomFacesMessage(TrMessageFactory.getSummaryString(key),
+                                        this._messages["range"],
                                         label,
                                         string,
+                                        ""+this._minValue,
                                         ""+this._maxValue);
+    	}
+    	else
+    	{
+        facesMessage = _createFacesMessage(key,
+                                        label,
+                                        string,
+                                        ""+this._minValue,
+                                        ""+this._maxValue);
+    	}
     }
-    else
-    {
-      facesMessage = _createFacesMessage("org.apache.myfaces.trinidad.validator.LongRangeValidator.MINIMUM",
+  }
+  else
+  {
+  	//only min
+  	if(this._minValue)
+  	{
+  		if(numberValue >= this._minValue)
+  		{
+  			return string;
+  		}
+  		else
+  		{
+        var key = "org.apache.myfaces.trinidad.validator.LongRangeValidator.MINIMUM";
+        if(this._messages && this._messages["min"])
+        {
+          facesMessage = _createCustomFacesMessage(TrMessageFactory.getSummaryString(key),
+                                        this._messages["min"],
                                         label,
                                         string,
                                         ""+this._minValue);
-    }
-    throw new TrConverterException(facesMessage);
+        }
+        else
+        {
+          facesMessage = _createFacesMessage(key,
+                                        label,
+                                        string,
+                                        ""+this._minValue);
+        }
+  		}
+  	}
+  	//max only
+  	else
+  	{
+  		if(numberValue <= this._maxValue)
+  		{
+  			return string;
+  		}
+  		else
+  		{
+        var key = "org.apache.myfaces.trinidad.validator.LongRangeValidator.MAXIMUM";
+        if(this._messages && this._messages["max"])
+        {
+          facesMessage = _createCustomFacesMessage(TrMessageFactory.getSummaryString(key),
+                                        this._messages["max"],
+                                        label,
+                                        string,
+                                        ""+this._maxValue);
+        }
+        else
+        {
+          facesMessage = _createFacesMessage(key,
+                                        label,
+                                        string,
+                                        ""+this._maxValue);
+        }
+  		}
+  	}
   }
+  throw new TrConverterException(facesMessage);
 }
 
 function TrLengthValidator(



Mime
View raw message