commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Niall Pemberton (JIRA)" <j...@apache.org>
Subject [jira] Updated: (VALIDATOR-169) Field validation for a list of fields
Date Thu, 23 Nov 2006 09:07:05 GMT
     [ http://issues.apache.org/jira/browse/VALIDATOR-169?page=all ]

Niall Pemberton updated VALIDATOR-169:
--------------------------------------

      Bugzilla Id:   (was: 22046)
          Summary: Field validation for a list of fields  (was: [validator] Field validation
for a list of fields)
    Fix Version/s: Validator2

> Field validation for a list of fields
> -------------------------------------
>
>                 Key: VALIDATOR-169
>                 URL: http://issues.apache.org/jira/browse/VALIDATOR-169
>             Project: Commons Validator
>          Issue Type: Improvement
>          Components: Framework
>         Environment: Operating System: other
> Platform: Other
>            Reporter: Jovovich
>            Priority: Minor
>             Fix For: Validator2
>
>         Attachments: patch.txt
>
>
> I have a JSP with a list of fields and I'm using the Validator in combination with Struts
for validating the field entries. The current behaviour of the Validator in case of a failed
validation is stopping the validation for the whole list of fields. It would be much better,
if the validator is processing the list of fields in any case. As a JSP programmer, I am able
to show an error message for _each_ wrong field of the list.
> This can be fixed with a small change in class Validator.java method validateField. Instead
of doing a return statement in the inner loop, just call the break statement, so the outer
loop can continue its work.
>     private void validateField(Field field, ValidatorResults allResults)
>         throws ValidatorException {
>         Map actions = resources.getValidatorActions();
>         if (field.isIndexed()) {
>             Object oIndexed;
>             try {
>                 oIndexed =
>                     PropertyUtils.getProperty(
>                         hResources.get(BEAN_KEY),
>                         field.getIndexedListProperty());
>             } catch (Exception e) {
>                 log.error("in validateField", e);
>                 return;
>             }
>             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++) {
>                 ValidatorResults results = new ValidatorResults();
>                 StringTokenizer st = new StringTokenizer(field.getDepends(), 
> ",");
>                 while (st.hasMoreTokens()) {
>                     String depend = st.nextToken().trim();
>                     ValidatorAction action = (ValidatorAction) 
> actions.get(depend);
>                     if (action == null) {
>                         log.error(
>                             "No ValidatorAction called "
>                                 + depend
>                                 + " found for field "
>                                 + field.getProperty());
>                         return;
>                     }
>                     
>                     boolean good =
>                         validateFieldForRule(field, action, results, actions, 
> pos);
>                     allResults.merge(results);
>                     if (!good) {
>                         break;
>                     }
>                 }
>             }
> Thanks,
> Tobias

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message