incubator-adffaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mat...@apache.org
Subject svn commit: r487194 - in /incubator/adffaces/trunk/trinidad/trinidad-impl/src/main: java/org/apache/myfaces/trinidadinternal/validator/ javascript/META-INF/adf/jsLibs/
Date Thu, 14 Dec 2006 12:43:54 GMT
Author: matzew
Date: Thu Dec 14 04:43:53 2006
New Revision: 487194

URL: http://svn.apache.org/viewvc?view=rev&rev=487194
Log:
some js improvements (dateRestriction better performance);
added hook for hints from converters/validators

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

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/DateRestrictionValidator.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/DateRestrictionValidator.java?view=diff&rev=487194&r1=487193&r2=487194
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/DateRestrictionValidator.java
(original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/DateRestrictionValidator.java
Thu Dec 14 04:43:53 2006
@@ -16,16 +16,13 @@
 */
 
 import java.io.IOException;
-import java.util.Calendar;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
 
-import javax.faces.validator.ValidatorException;
-import javax.faces.context.FacesContext;
 import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.ValidatorException;
 
 import org.apache.myfaces.trinidad.validator.ClientValidator;
 import org.apache.myfaces.trinidadinternal.convert.GenericConverterFactory;
@@ -41,7 +38,6 @@
   public DateRestrictionValidator()
   {
     super();
-    _initJsDateMap();
   }
 
   @Override
@@ -125,56 +121,11 @@
     outBuffer.append(weekdaysValues);
     outBuffer.append(',');
     outBuffer.append(monthValues);
-    outBuffer.append(',');
-    outBuffer.append(_getMapAsJson(_jsWeekDays));
-    outBuffer.append(',');
-    outBuffer.append(_getMapAsJson(_jsMonths));
     outBuffer.append(")");
 
     return outBuffer.toString();
   }
   
-  private static String _getMapAsJson(Map map)
-  {
-    StringBuilder sb = new StringBuilder();
-    try
-    {
-      JsonUtils.writeMap(sb, map, false);
-    }
-    catch (IOException e)
-    {
-      sb.append("null");
-    }
-    return sb.toString();
-  }
-  
-  private void _initJsDateMap()
-  {
-    _jsWeekDays = new HashMap<Integer, String>();
-    _jsWeekDays.put(Calendar.SUNDAY-1, "sun");
-    _jsWeekDays.put(Calendar.MONDAY-1, "mon");
-    _jsWeekDays.put(Calendar.TUESDAY-1, "tue");
-    _jsWeekDays.put(Calendar.WEDNESDAY-1, "wed");
-    _jsWeekDays.put(Calendar.THURSDAY-1, "thu");
-    _jsWeekDays.put(Calendar.FRIDAY-1, "fri");
-    _jsWeekDays.put(Calendar.SATURDAY-1, "sat");
-    
-    _jsMonths = new HashMap<Integer, String>();
-    _jsMonths.put(Calendar.JANUARY, "jan");
-    _jsMonths.put(Calendar.FEBRUARY, "feb");
-    _jsMonths.put(Calendar.MARCH, "mar");
-    _jsMonths.put(Calendar.APRIL, "apr");
-    _jsMonths.put(Calendar.MAY, "may");
-    _jsMonths.put(Calendar.JUNE, "jun");
-    _jsMonths.put(Calendar.JULY, "jul");
-    _jsMonths.put(Calendar.AUGUST, "aug");
-    _jsMonths.put(Calendar.SEPTEMBER, "sep");
-    _jsMonths.put(Calendar.OCTOBER, "oct");
-    _jsMonths.put(Calendar.NOVEMBER, "nov");
-    _jsMonths.put(Calendar.DECEMBER, "dec");
-  }
   
   private static final Collection<String> _IMPORT_NAMES = Collections.singletonList(
"TrNumberConverter()" );
-  private static Map<Integer, String> _jsMonths = null;
-  private static Map<Integer, String> _jsWeekDays = null;
 }

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CharSets.js
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CharSets.js?view=diff&rev=487194&r1=487193&r2=487194
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CharSets.js
(original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CharSets.js
Thu Dec 14 04:43:53 2006
@@ -41,6 +41,17 @@
 }
 
 CjkFormat.prototype = new TrByteLengthValidator();
+CjkFormat.prototype.getHints = function(
+  converter
+  )
+{
+  var messages = new Array();
+  messages.push(TrMessageFactory.createMessage(
+    "org.apache.myfaces.trinidad.validator.ByteLengthValidator.MAXIMUM_HINT",
+	  this._length)
+	);
+	return messages;
+}
 CjkFormat.prototype.validate  = function(
   parseString,
   label,
@@ -97,6 +108,17 @@
 
 
 Utf8Format.prototype = new TrByteLengthValidator();
+Utf8Format.prototype.getHints = function(
+  converter
+  )
+{
+  var messages = new Array();
+  messages.push(TrMessageFactory.createMessage(
+    "org.apache.myfaces.trinidad.validator.ByteLengthValidator.MAXIMUM_HINT",
+	  this._length)
+	);
+	return messages;
+}
 Utf8Format.prototype.validate  = function(
   parseString,
   label,
@@ -159,6 +181,17 @@
 
 
 SBFormat.prototype = new TrByteLengthValidator();
+SBFormat.prototype.getHints = function(
+  converter
+  )
+{
+  var messages = new Array();
+  messages.push(TrMessageFactory.createMessage(
+    "org.apache.myfaces.trinidad.validator.ByteLengthValidator.MAXIMUM_HINT",
+	  this._length)
+	);
+	return messages;
+}
 SBFormat.prototype.validate  = function(
   parseString,
   label,

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/ColorFormat.js
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/ColorFormat.js?view=diff&rev=487194&r1=487193&r2=487194
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/ColorFormat.js
(original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/ColorFormat.js
Thu Dec 14 04:43:53 2006
@@ -41,6 +41,13 @@
 }
 
 TrColorConverter.prototype = new TrConverter();
+
+TrColorConverter.prototype.getFormatHint = function()
+{
+	return TrMessageFactory.createMessage(
+    "org.apache.myfaces.trinidad.convert.ColorConverter.FORMAT_HINT",
+	  this._pattern);
+}
 TrColorConverter.prototype.getAsString = function(
   formatColor)
 {

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=487194&r1=487193&r2=487194
==============================================================================
--- 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
Thu Dec 14 04:43:53 2006
@@ -33,6 +33,12 @@
 
 TrIntegerConverter.prototype = new TrConverter();
 
+TrIntegerConverter.prototype.getFormatHint = function()
+{
+	return TrMessageFactory.createMessage(
+    "org.apache.myfaces.trinidad.convert.IntegerConverter.FORMAT_HINT",
+	  null);
+}
 
 TrIntegerConverter.prototype.getAsString = function(
   number,
@@ -75,6 +81,12 @@
 
 TrLongConverter.prototype = new TrConverter();
 
+TrLongConverter.prototype.getFormatHint = function()
+{
+	return TrMessageFactory.createMessage(
+    "org.apache.myfaces.trinidad.convert.LongConverter.FORMAT_HINT",
+	  null);
+}
 
 TrLongConverter.prototype.getAsString = function(
   number,
@@ -117,6 +129,12 @@
 
 TrShortConverter.prototype = new TrConverter();
 
+TrShortConverter.prototype.getFormatHint = function()
+{
+	return TrMessageFactory.createMessage(
+    "org.apache.myfaces.trinidad.convert.ShortConverter.FORMAT_HINT",
+	  null);
+}
 
 TrShortConverter.prototype.getAsString = function(
   number,
@@ -159,6 +177,12 @@
 
 TrByteConverter.prototype = new TrConverter();
 
+TrByteConverter.prototype.getFormatHint = function()
+{
+	return TrMessageFactory.createMessage(
+    "org.apache.myfaces.trinidad.convert.ByteConverter.FORMAT_HINT",
+	  null);
+}
 
 TrByteConverter.prototype.getAsString = function(
   number,
@@ -202,6 +226,12 @@
 
 TrDoubleConverter.prototype = new TrConverter();
 
+TrDoubleConverter.prototype.getFormatHint = function()
+{
+	return TrMessageFactory.createMessage(
+    "org.apache.myfaces.trinidad.convert.DoubleConverter.FORMAT_HINT",
+	  null);
+}
 
 TrDoubleConverter.prototype.getAsString = function(
   number,
@@ -244,6 +274,13 @@
 
 TrFloatConverter.prototype = new TrConverter();
 
+TrFloatConverter.prototype.getFormatHint = function()
+{
+	return TrMessageFactory.createMessage(
+    "org.apache.myfaces.trinidad.convert.FloatConverter.FORMAT_HINT",
+	  null);
+}
+
 TrFloatConverter.prototype.getAsString = function(
   number,
   label
@@ -280,6 +317,24 @@
 }
 
 TrRangeValidator.prototype = new TrValidator();
+TrRangeValidator.prototype.getHints = function(
+  converter
+  )
+{
+	var hints = new Array();
+	hints.push(
+  	TrMessageFactory.createMessage(
+      "org.apache.myfaces.trinidad.validator.RangeValidator.MAXIMUM_HINT",
+	    ""+this._maxValue)
+   );
+	hints.push(
+  	TrMessageFactory.createMessage(
+      "org.apache.myfaces.trinidad.validator.RangeValidator.MINIMUM_HINT",
+	    ""+this._minValue)
+   );
+
+  return hints;
+}
 TrRangeValidator.prototype.validate  = function(
   value,
   label,
@@ -327,6 +382,17 @@
 }
 
 TrLengthValidator.prototype = new TrValidator();
+TrLengthValidator.prototype.getHints = function(
+  converter
+  )
+{
+  return _returnHints(
+    this._maxValue,
+    this._minValue,
+    "org.apache.myfaces.trinidad.validator.LengthValidator.MAXIMUM_HINT",
+    "org.apache.myfaces.trinidad.validator.LengthValidator.MINIMUM_HINT"
+  );
+}
 TrLengthValidator.prototype.validate  = function(
   value,
   label,
@@ -365,6 +431,17 @@
 }
 
 TrDateTimeRangeValidator.prototype = new TrValidator();
+TrDateTimeRangeValidator.prototype.getHints = function(
+  converter
+  )
+{
+  return _returnHints(
+    converter.getAsString(new Date(this._maxValue)),
+    converter.getAsString(new Date(this._minValue)),
+    "org.apache.myfaces.trinidad.validator.DateTimeRangeValidator.MAXIMUM_HINT",
+    "org.apache.myfaces.trinidad.validator.DateTimeRangeValidator.MINIMUM_HINT"
+  );
+}
 TrDateTimeRangeValidator.prototype.validate  = function(
   value,
   label,
@@ -393,20 +470,29 @@
 
 function TrDateRestrictionValidator(
   weekdaysValue,
-  monthValue,
-  weekdaysMap,
-  monthMap)
+  monthValue)
 {
   this._weekdaysValue = weekdaysValue;
   this._monthValue = monthValue;
-  this._weekdaysMap = weekdaysMap;
-  this._monthMap = monthMap;
+  this._weekdaysMap = {'2':'tue','4':'thu','6':'sat','1':'mon','3':'wed','5':'fri','0':'sun'};
+  this._monthMap = {'2':'mar','4':'may','9':'oct','8':'sep','11':'dec','6':'jul','1':'feb','3':'apr','10':'nov','7':'aug','5':'jun','0':'jan'};
 
   // for debugging
   this._class = "TrDateRestrictionValidator";
 }
 
 TrDateRestrictionValidator.prototype = new TrValidator();
+TrDateRestrictionValidator.prototype.getHints = function(
+  converter
+  )
+{
+  return _returnHints(
+    this._weekdaysValue,
+    this._monthValue,
+    "org.apache.myfaces.trinidad.validator.DateRestrictionValidator.WEEKDAY_HINT",
+    "org.apache.myfaces.trinidad.validator.DateRestrictionValidator.MONTH_HINT"
+  );
+}
 TrDateRestrictionValidator.prototype.validate  = function(
   value,
   label,
@@ -424,7 +510,7 @@
   		{
         facesMessage = _createFacesMessage("org.apache.myfaces.trinidad.validator.DateRestrictionValidator.WEEKDAY",
                                         label,
-                                        ""+value,
+                                        ""+converter.getAsString(value),
                                         dayString);
         throw new TrConverterException(facesMessage);
   		}
@@ -442,7 +528,7 @@
   		{
         facesMessage = _createFacesMessage("org.apache.myfaces.trinidad.validator.DateRestrictionValidator.MONTH",
                                         label,
-                                        ""+value,
+                                        ""+converter.getAsString(value),
                                         monthString);
         throw new TrConverterException(facesMessage);
   		}
@@ -584,6 +670,17 @@
 }
 
 TrRegExpValidator.prototype = new TrValidator();
+TrRegExpValidator.prototype.getHints = function(
+  converter
+  )
+{
+  var hints = new Array();
+  hints.push(TrMessageFactory.createMessage(
+      "org.apache.myfaces.trinidad.validator.RegExpValidator.NO_MATCH_HINT",
+      ""+this._pattern)
+  );
+  return hints;
+}
 TrRegExpValidator.prototype.validate  = function(
   parseString,
   label,
@@ -620,4 +717,36 @@
     }
     throw new TrValidatorException(facesMessage); 
   }
+}
+
+function _returnHints(
+  max,
+  min,
+  maxKey,
+  minKey
+)
+{
+  var hints = null;
+  if(max)
+  {
+    hints = new Array();
+    hints.push(
+      TrMessageFactory.createMessage(
+        maxKey,
+	      ""+max)
+	  );
+  }
+  if(min)
+  {
+    if(!hints)
+    {
+      hints = new Array();
+    }
+    hints.push(
+      TrMessageFactory.createMessage(
+        minKey,
+	      ""+min)
+     );
+  }
+  return hints;
 }

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/DateFormat.js
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/DateFormat.js?view=diff&rev=487194&r1=487193&r2=487194
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/DateFormat.js
(original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/DateFormat.js
Thu Dec 14 04:43:53 2006
@@ -1049,6 +1049,14 @@
 }
 
 TrDateTimeConverter.prototype = new TrConverter();
+
+TrDateTimeConverter.prototype.getFormatHint = function()
+{
+	return TrMessageFactory.createMessage(
+    "org.apache.myfaces.trinidad.convert.DateTimeConverter.FORMAT_HINT",
+    this._pattern);
+}
+
 TrDateTimeConverter.prototype.getAsString = function(
   formatTime
   )

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Locale.js
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Locale.js?view=diff&rev=487194&r1=487193&r2=487194
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Locale.js
(original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Locale.js
Thu Dec 14 04:43:53 2006
@@ -549,6 +549,46 @@
 LocaleSymbols.prototype.getLocaleElements = _getLocaleElements;
 
 /**
+ * ConverterHint "interface" for a client side TrConverter instance.
+ * The ConverterHint "interface" is for guiding a user on the desired format to ensure
+ * that no converter exceptions are thrown.
+ *
+ */
+function TrConverterHint()
+{
+  // for debugging
+  this._class = "TrConverterHint";
+}
+
+/**
+ * Returns a hint for the used converter, which format is
+ * expected by the ui component.
+ */
+TrConverterHint.prototype.getFormatHint = function(){}
+
+/**
+ * ValidatorHint "interface" for a client side TrValidator instance.
+ * The ValidatorHint "interface" is to guide a user when entering a
+ * value to an input component, to ensure that no validator exceptions is thrown.
+ */
+function TrValidatorHint()
+{
+  // for debugging
+  this._class = "TrValidatorHint";
+}
+
+/**
+ * Since an implementation of this "interface" can have multiple
+ * hints available, we return all available hint messages in an JavaScript Array.
+ * 
+ * @param converter converter is passed to this method, because sometimes a default converter
is used
+ * and the validator, implementing this interface, shouldn't need to figure out
+ * anything about that
+ */
+TrConverterHint.prototype.getHints = function(converter){}
+
+
+/**
  * Converter "interface" similar to javax.faces.convert.Converter,
  * except that all relevant information must be passed to the constructor
  * as the context and component are not passed to the getAsString or getAsObject method 
@@ -852,4 +892,29 @@
     
   // TODO should I be doing string concat here, or have a map of key -> detailKey?
   return TrMessageFactory._TRANSLATIONS[key+"_detail"];
+}
+
+TrMessageFactory.getString = function(
+  key
+  )
+{
+  return TrMessageFactory.getSummaryString(key);
+}
+
+TrMessageFactory.createMessage = function(
+  key,
+  parameters
+  )
+{  
+  // the strings to create a facesMessage to use have been sent down
+  var message = TrMessageFactory.getSummaryString(key);       
+  if ( message != null )
+  {
+    if ( parameters != null )
+    {
+      message = TrFastMessageFormatUtils.format(message,parameters);
+    }
+  }
+    
+  return message;
 }



Mime
View raw message