You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by aw...@apache.org on 2007/07/11 02:34:29 UTC

svn commit: r555126 - in /myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml: CoreFormData.java FormRenderer.java

Author: awiner
Date: Tue Jul 10 17:34:28 2007
New Revision: 555126

URL: http://svn.apache.org/viewvc?view=rev&rev=555126
Log:
Step 1 of TRINIDAD-96: Validators should be added incrementally, not set as a whole
- Instead of storing the client validator info in a list, store it in a Map
  of Lists, so that we can start to iterate by client ID

Modified:
    myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/CoreFormData.java
    myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/FormRenderer.java

Modified: myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/CoreFormData.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/CoreFormData.java?view=diff&rev=555126&r1=555125&r2=555126
==============================================================================
--- myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/CoreFormData.java (original)
+++ myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/CoreFormData.java Tue Jul 10 17:34:28 2007
@@ -241,14 +241,14 @@
     return errorFormatMap.keySet().iterator();
   }
 
-  public List<ConvertValidate> getFormValidatorsInfo(
+  public Map<String, List<ConvertValidate>> getFormValidatorsInfo(
     boolean createIfNecessary
     )
   {
     // create the validators if they don't already exist
     if ((_formValidatorsInfo == null) && createIfNecessary)
     {
-      _formValidatorsInfo = new ArrayList<ConvertValidate>();
+      _formValidatorsInfo = new HashMap<String, List<ConvertValidate>>();
     }
 
     return _formValidatorsInfo;
@@ -368,7 +368,8 @@
    */
   private void _addFormConverterInfo(
     String                    converter,
-    CoreFormData.ConvertValidate  convertValidate
+    CoreFormData.ConvertValidate  convertValidate,
+    String                    clientId
    )
   {
     if (converter != null && convertValidate != null)
@@ -376,7 +377,7 @@
       if (convertValidate.converter == null)
         convertValidate.converter = new Object[2];
       else
-        _LOG.warning("DUPLICATE_CONVERTER_ONE_PER_COMPONENT", convertValidate.clientId);
+        _LOG.warning("DUPLICATE_CONVERTER_ONE_PER_COMPONENT", clientId);
 
 
       // add the converter
@@ -438,7 +439,7 @@
     if (converter != null)
     {
 
-      _addFormConverterInfo( converter, convertValidate);
+      _addFormConverterInfo( converter, convertValidate, clientId);
       _addValidatedInput(clientId);
     }
   }
@@ -578,13 +579,16 @@
       // create
       ConvertValidate convertValidateInfo = new ConvertValidate();
 
-      // set name
-      convertValidateInfo.clientId = clientId;
-
       // add to list
-      List<ConvertValidate> convertValidateList = getFormValidatorsInfo(true);
-      convertValidateList.add(convertValidateInfo);
+      Map<String, List<ConvertValidate>> map = getFormValidatorsInfo(true);
+      List<ConvertValidate> convertValidateList = map.get(clientId);
+      if (convertValidateList == null)
+      {
+        convertValidateList = new ArrayList<ConvertValidate>();
+        map.put(clientId, convertValidateList);
+      }
 
+      convertValidateList.add(convertValidateInfo);
       return convertValidateInfo;
   }
 
@@ -736,7 +740,7 @@
   private Map<String, Integer> _errorFormatMap = null;
 
   // List of ConvertValidate objects
-  private List<ConvertValidate> _formValidatorsInfo;
+  private Map<String, List<ConvertValidate>> _formValidatorsInfo;
 
   // javascript needed for client validations
   private List<String> _clientDependencies;
@@ -766,7 +770,6 @@
 
  public static final class ConvertValidate
   {
-    public String             clientId;
     public boolean            required = false;
     public Integer            requiredFormatIndex;
     public ArrayList<Integer> validators;

Modified: myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/FormRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/FormRenderer.java?view=diff&rev=555126&r1=555125&r2=555126
==============================================================================
--- myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/FormRenderer.java (original)
+++ myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/FormRenderer.java Tue Jul 10 17:34:28 2007
@@ -537,99 +537,107 @@
     //
     // Write the array of form validators
     //
-    List<CoreFormData.ConvertValidate> validatorInfoList =
+    Map<String, List<CoreFormData.ConvertValidate>> validatorInfoMap =
       fData.getFormValidatorsInfo(false);
     
-    if (validatorInfoList != null)
+    if (validatorInfoMap != null)
     {
       writer.writeText("var _", null);
       writer.writeText(jsID, null);
       writer.writeText("_Validators=[", null);
   
-      boolean firstFormInfo = true;
 
-      for (int j = 0; j < validatorInfoList.size(); j++)
+      boolean firstFormInfo = true;
+      for (Map.Entry<String, List<CoreFormData.ConvertValidate>> validatorEntry  :
+           validatorInfoMap.entrySet())
       {
-
-        if (firstFormInfo)
+        String clientId = validatorEntry.getKey();
+        List<CoreFormData.ConvertValidate> validatorInfoList =
+          validatorEntry.getValue();
+      
+        for (CoreFormData.ConvertValidate convertValidate : validatorInfoList)
         {
-          firstFormInfo = false;
-        }
-        else
-        {
-          // write the separator every time except the first time
-          writer.writeText("],", null);
-        }
-
-        CoreFormData.ConvertValidate convertValidate = validatorInfoList.get(j);
-
-        writer.writeText("\"", null);
-
-        // write the element name of the element to be validated
-        writer.writeText(convertValidate.clientId, null);
-        writer.writeText("\",", null);
-
-        // write out whether or not this element is required
-        writer.writeText(convertValidate.required? "1" : "0", null);
-        writer.writeText(",", null);
-
-        if (convertValidate.requiredFormatIndex != null)
-        {
-          // write out the index of the required error message
-          writer.writeText(convertValidate.requiredFormatIndex, null);
-        }
-
-        writer.writeText(",", null);
-
-        Object converterInfo = convertValidate.converter;
-
-        if (converterInfo != null)
-        {
-          writer.writeText(converterInfo, null);
-        }
-        else
-        {
-          writer.writeText("(void 0)", null);
-        }
-
-        writer.writeText(",[", null);
-
-        ArrayList<Integer> validatorInfo = convertValidate.validators;
-
-        if (validatorInfo != null)
-        {
-          boolean firstValidator = true;
+          
+          if (firstFormInfo)
+          {
+            firstFormInfo = false;
+          }
+          else
+          {
+            // write the separator every time except the first time
+            writer.writeText("],", null);
+          }
+          
+          writer.writeText("\"", null);
+          
+          // write the element name of the element to be validated
+          writer.writeText(clientId, null);
+          writer.writeText("\",", null);
+
+          // write out whether or not this element is required
+          writer.writeText(convertValidate.required? "1" : "0", null);
+          writer.writeText(",", null);
+          
+          if (convertValidate.requiredFormatIndex != null)
+          {
+            // write out the index of the required error message
+            writer.writeText(convertValidate.requiredFormatIndex, null);
+          }
+          
+          writer.writeText(",", null);
+          
+          Object converterInfo = convertValidate.converter;
+          
+          if (converterInfo != null)
+          {
+            writer.writeText(converterInfo, null);
+          }
+          else
+          {
+            writer.writeText("(void 0)", null);
+          }
+          
+          writer.writeText(",[", null);
+          
+          ArrayList<Integer> validatorInfo = convertValidate.validators;
 
-          int i = 0;
-          while (i < validatorInfo.size())
+          if (validatorInfo != null)
           {
-            if (firstValidator)
-            {
-              firstValidator = false;
-            }
-            else
+            boolean firstValidator = true;
+            
+            int i = 0;
+            while (i < validatorInfo.size())
             {
-              // write the separator every time except the first time
-              writer.writeText(",", null);
+              if (firstValidator)
+              {
+                firstValidator = false;
+              }
+              else
+              {
+                // write the separator every time except the first time
+                writer.writeText(",", null);
+              }
+              
+              // write the validation string for the validater
+              writer.writeText(validatorInfo.get(i).toString(), null);
+              
+              i = i + 1;
             }
-
-            // write the validation string for the validater
-            writer.writeText(validatorInfo.get(i).toString(), null);
-
-            i = i + 1;
           }
         }
       }
-  
+
       writer.writeText("]];", null);
     }
+
     //
     // write the validation function for this form
     //
+    // FIXME: hoist this out of the PPR block
     writer.writeText("function _", null);
     writer.writeText(jsID, null);
 
-    if (validatorInfoList == null)
+    if (validatorInfoMap == null)
     {
       // no validation, so validation always succeeds
       writer.writeText("Validator(){return true;}", null);