dwinterfeldt 01/10/17 23:03:32 Modified: contrib/validator/src/share/com/wintecinc/struts/validation Field.java Validator.java ValidatorResources.java Log: When indexed property support was added, it broke the cloning of non-default loccale FormSets. The getKey method in Field was returning null because the Field's process method hadn't been called yet. Revision Changes Path 1.5 +36 -14 jakarta-struts/contrib/validator/src/share/com/wintecinc/struts/validation/Field.java Index: Field.java =================================================================== RCS file: /home/cvs/jakarta-struts/contrib/validator/src/share/com/wintecinc/struts/validation/Field.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- Field.java 2001/09/25 21:23:56 1.4 +++ Field.java 2001/10/18 06:03:32 1.5 @@ -393,6 +393,9 @@ * Gets a unique key based on the property and indexedProperty fields. */ public String getKey() { + if (key == null) + generateKey(); + return key; } @@ -415,8 +418,18 @@ else return false; } - + /** + * Generate correct <code>key</code> value. + */ + public void generateKey() { + if (isIndexed()) + key = indexedProperty + TOKEN_INDEXED + "." + property; + else + key = property; + } + + /** * Replace constants with values in fields and process the depends field * to create the dependency <code>Map</code>. */ @@ -428,13 +441,8 @@ hArg3.setFast(true); hVars.setFast(true); - // If the field is indexed, combine property and - // indexedProperty to make a unique key. - if (isIndexed()) - key = indexedProperty + TOKEN_INDEXED + "." + property; - else - key = property; - + generateKey(); + // Process FormSet Constants for (Iterator i = constants.keySet().iterator(); i.hasNext(); ) { String key = (String)i.next(); @@ -557,13 +565,22 @@ try { Field field = (Field)super.clone(); + if (key != null) + field.setKey(new String(key)); + if (property != null) field.setProperty(new String(property)); + + if (indexedProperty != null) + field.setIndexedProperty(new String(indexedProperty)); + + if (indexedListProperty != null) + field.setIndexedListProperty(new String(indexedListProperty)); if (depends != null) field.setDepends(new String(depends)); - - // page field taken care of by clone method + + // page & fieldOrder should be taken care of by clone method field.hDependencies = copyFastHashMap(hDependencies); field.hVars = copyFastHashMap(hVars); @@ -572,7 +589,7 @@ field.hArg1 = copyFastHashMap(hArg1); field.hArg2 = copyFastHashMap(hArg2); field.hArg3 = copyFastHashMap(hArg3); - + return field; } catch (CloneNotSupportedException e) { throw new InternalError(e.toString()); @@ -610,9 +627,14 @@ } public String toString() { - String sReturn = "\t\tproperty= " + property + "\n" + - "\t\tdepends= " + depends + "\n"; - + String sReturn = "\t\tkey= " + key + "\n" + + "\t\tproperty= " + property + "\n" + + "\t\tindexedProperty= " + indexedProperty + "\n" + + "\t\tindexedListProperty= " + indexedListProperty + "\n" + + "\t\tdepends= " + depends + "\n" + + "\t\tpage= " + page + "\n" + + "\t\tfieldOrder= " + fieldOrder + "\n"; + if (hVars != null) { sReturn += "\t\tVars:\n"; for (Iterator i = hVars.keySet().iterator(); i.hasNext(); ) { 1.5 +15 -10 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.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- Validator.java 2001/09/25 20:08:48 1.4 +++ Validator.java 2001/10/18 06:03:32 1.5 @@ -209,10 +209,12 @@ String depend = st.nextToken().trim(); Object o = hActionsRun.get(depend); - //logger.info("***### Validator main - " + va.getName() + " - " + va.getDepends()); + //if (logger.getDebug() > 10) + // logger.info("***### Validator main - " + va.getName() + " - " + va.getDepends()); if (o == null) { - //logger.info("***### Validator o==null - " + va.getName() + " - " + va.getDepends()); + //if (logger.getDebug() > 10) + // logger.info("***### Validator o==null - " + va.getName() + " - " + va.getDepends()); lActions.clear(); va = null; @@ -221,7 +223,8 @@ } else { boolean bContinue = ((Boolean)o).booleanValue(); - //logger.info("***### Validator - " + va.getName() + " depend=" + depend + " bContinue=" + bContinue); + //if (logger.getDebug() > 10) + // logger.info("***### Validator - " + va.getName() + " depend=" + depend + " bContinue=" + bContinue); if (!bContinue) { lActions.clear(); @@ -237,7 +240,7 @@ } // For debug - /*if (logger.getDebug() > 0) { + /**if (logger.getDebug() > 10) { logger.info("***Order ******************************"); for (Iterator actions = lActions.iterator(); actions.hasNext(); ) { @@ -251,14 +254,14 @@ if (va != null) { for (Iterator i = form.getFields().iterator(); i.hasNext(); ) { Field field = (Field)i.next(); - + if (field.getPage() <= page && (field.getDepends() != null && field.isDependency(va.getName()))) { try { // Add these two Objects to the resources since they reference // the current validator action and field hResources.put(VALIDATOR_ACTION_KEY, va); hResources.put(FIELD_KEY, field); - + Class c = Class.forName(va.getClassname(), true, this.getClass().getClassLoader()); List lParams = va.getMethodParamsList(); @@ -296,7 +299,7 @@ "of class " + va.getClassname() + ". " + ex.getMessage()); } } - + Object result = null; if (field.isIndexed()) { @@ -328,7 +331,7 @@ } } else { result = m.invoke(va.getClassnameInstance(), paramValue); - + if (result instanceof Boolean) { Boolean valid = (Boolean)result; if (!valid.booleanValue()) @@ -352,12 +355,14 @@ hActionsRun.put(va.getName(), new Boolean(false)); } - //logger.info("*** Validator - " + va.getName() + " size=" + lActions.size()); + if (logger.getDebug() > 10) + logger.info("*** Validator - " + va.getName() + " size=" + lActions.size()); if (lActions.size() > 0) lActions.remove(0); - //logger.info("*** Validator - after remove - " + va.getName() + " size=" + lActions.size()); + if (logger.getDebug() > 10) + logger.info("*** Validator - after remove - " + va.getName() + " size=" + lActions.size()); } if (lActions.size() == 0) 1.4 +0 -2 jakarta-struts/contrib/validator/src/share/com/wintecinc/struts/validation/ValidatorResources.java Index: ValidatorResources.java =================================================================== RCS file: /home/cvs/jakarta-struts/contrib/validator/src/share/com/wintecinc/struts/validation/ValidatorResources.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ValidatorResources.java 2001/09/25 18:03:12 1.3 +++ ValidatorResources.java 2001/10/18 06:03:32 1.4 @@ -395,8 +395,6 @@ !GenericValidator.isBlankOrNull(variant)) { Form form = get(language, country, null, formKey); - // FIX ME - getFieldMap() can be removed if method in this class - // can loop through and find the matching field based on the Field.getProperty() if (form.getFieldMap().containsKey(fieldKey)) field = (Field)form.getFieldMap().get(fieldKey); }