dwinterfeldt    01/09/25 11:01:39

  Modified:    contrib/validator/src/share/com/wintecinc/struts/validation
                        Validator.java
  Log:
  Added functionality to support indexed validation.
  
  Revision  Changes    Path
  1.3       +48 -8     
jakarta-struts/contrib/validator/src/share/com/wintecinc/struts/validation/Validator.java
  
  Index: Validator.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-struts/contrib/validator/src/share/com/wintecinc/struts/validation/Validator.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Validator.java    2001/08/17 17:40:49     1.2
  +++ Validator.java    2001/09/25 18:01:39     1.3
  @@ -57,6 +57,7 @@
   
   import java.io.Serializable;
   import java.util.ArrayList;
  +import java.util.Collection;
   import java.util.Collections;
   import java.util.Comparator;
   import java.util.HashMap;
  @@ -276,12 +277,20 @@
                          
                          List lParams = va.getMethodParamsList();
                          int size = lParams.size();
  +                       int beanIndexPos = -1;
  +                       int fieldIndexPos = -1;
                          Class[] paramClass = new Class[size];
                          Object[] paramValue = new Object[size];
   
                          for (int x = 0; x < size; x++) {
                             String paramKey = (String)lParams.get(x);
  -                          
  +                                  
  +                                  if (BEAN_KEY.equals(paramKey))
  +                                     beanIndexPos = x;
  +                                     
  +                                  if (FIELD_KEY.equals(paramKey))
  +                                     fieldIndexPos = x;
  +                                  
                             // There were problems calling getClass on paramValue[]
                             paramClass[x] = Class.forName(paramKey, true, 
this.getClass().getClassLoader());
                             paramValue[x] = hResources.get(paramKey);
  @@ -301,13 +310,44 @@
                                           "of class " + va.getClassname() + ".  " + 
ex.getMessage());   
                             }
                          }
  -
  -                          Object result = m.invoke(va.getClassnameInstance(), 
paramValue);
  -
  -                          if (result instanceof Boolean) {
  -                             Boolean valid = (Boolean)result;
  -                             if (!valid.booleanValue())
  -                                iErrorCount++;
  +                          
  +                          Object result = null;
  +                          
  +                          if (field.isIndexed()) {
  +                             Object oIndexed = 
PropertyUtils.getProperty(hResources.get(BEAN_KEY), field.getIndexedListProperty());
  +                             Object indexedList[] = new Object[0];
  +                             
  +                             if (oIndexed instanceof Collection)
  +                                indexedList = ((Collection)oIndexed).toArray();
  +                             else if(oIndexed.getClass().isArray())
  +                                indexedList = (Object[])oIndexed;
  +                             
  +                             for (int pos = 0; pos < indexedList.length; pos++) {
  +                                // Set current iteration object to the parameter 
array
  +                                paramValue[beanIndexPos] = indexedList[pos];
  +                                
  +                                // Set field clone with the key modified to 
represent 
  +                                // the current field
  +                                Field indexedField = (Field)field.clone();
  +                                
indexedField.setKey(ValidatorUtil.replace(indexedField.getKey(), Field.TOKEN_INDEXED, 
"[" + pos + "]"));
  +                                paramValue[fieldIndexPos] = indexedField;
  +                                
  +                                     result = m.invoke(va.getClassnameInstance(), 
paramValue);
  +
  +                                if (result instanceof Boolean) {
  +                                   Boolean valid = (Boolean)result;
  +                                   if (!valid.booleanValue())
  +                                      iErrorCount++;
  +                                }
  +                             }
  +                          } else {
  +                             result = m.invoke(va.getClassnameInstance(), 
paramValue);
  +                             
  +                             if (result instanceof Boolean) {
  +                                Boolean valid = (Boolean)result;
  +                                if (!valid.booleanValue())
  +                                   iErrorCount++;
  +                             }
                             }
                       } catch (Exception e) {
                          bErrors = true;
  
  
  

Reply via email to