You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Ed Cavalari <ed...@gmail.com> on 2006/03/15 14:30:10 UTC
commons-validator indexed properties
Hi,
I would like to be able to run the validation on every item in a list and
I'm finding that as soon as one of the elements fails validation, the
validator stops and the remaining items in the list are not validated. I
took a look at the source code and this is what I found.
ValidatorResults validate(Map params, Map actions)
throws ValidatorException {
if (this.getDepends() == null) {
return new ValidatorResults();
}
ValidatorResults allResults = new ValidatorResults();
Object bean = params.get(Validator.BEAN_PARAM);
int numberOfFieldsToValidate =
this.isIndexed() ? this.getIndexedProperty(bean).length : 1;
for (int fieldNumber = 0; fieldNumber < numberOfFieldsToValidate;
fieldNumber++) {
Iterator dependencies = this.dependencyList.iterator();
while (dependencies.hasNext()) {
String depend = (String) dependencies.next();
ValidatorAction action = (ValidatorAction) actions.get
(depend);
if (action == null) {
this.handleMissingAction(depend);
}
ValidatorResults results = new ValidatorResults();
boolean good =
validateForRule(action, results, actions, params,
fieldNumber);
allResults.merge(results);
if (!good) {
return allResults;
}
}
}
return allResults;
}
This method of the Field class appears to be the culprit of my problem. I
would like to suggest that the dtd and code be changed to allow for a flag
that allows all items in the list to be
processed,(processAllItems="true|false" default = false). Then the test
if (!good) {
return allResults;
}
could change to say,
if (!good)
{
if (processAllItems)
{
break;
}
else
{
return allResults;
}
}
I've changed the source to do the break and everything works as I would like
it to. Unfortunately my shop won't allow me to make this change for our
project, but it you guys make the change and release I can use it.
Thanks,
Ed
Re: commons-validator indexed properties
Posted by Niall Pemberton <ni...@blueyonder.co.uk>.
Theres an open bug for this
http://issues.apache.org/bugzilla/show_bug.cgi?id=22046
Niall
----- Original Message -----
From: "Ed Cavalari" <ed...@gmail.com>
To: <co...@jakarta.apache.org>
Sent: Wednesday, March 15, 2006 1:30 PM
Subject: commons-validator indexed properties
Hi,
I would like to be able to run the validation on every item in a list and
I'm finding that as soon as one of the elements fails validation, the
validator stops and the remaining items in the list are not validated. I
took a look at the source code and this is what I found.
ValidatorResults validate(Map params, Map actions)
throws ValidatorException {
if (this.getDepends() == null) {
return new ValidatorResults();
}
ValidatorResults allResults = new ValidatorResults();
Object bean = params.get(Validator.BEAN_PARAM);
int numberOfFieldsToValidate =
this.isIndexed() ? this.getIndexedProperty(bean).length : 1;
for (int fieldNumber = 0; fieldNumber < numberOfFieldsToValidate;
fieldNumber++) {
Iterator dependencies = this.dependencyList.iterator();
while (dependencies.hasNext()) {
String depend = (String) dependencies.next();
ValidatorAction action = (ValidatorAction) actions.get
(depend);
if (action == null) {
this.handleMissingAction(depend);
}
ValidatorResults results = new ValidatorResults();
boolean good =
validateForRule(action, results, actions, params,
fieldNumber);
allResults.merge(results);
if (!good) {
return allResults;
}
}
}
return allResults;
}
This method of the Field class appears to be the culprit of my problem. I
would like to suggest that the dtd and code be changed to allow for a flag
that allows all items in the list to be
processed,(processAllItems="true|false" default = false). Then the test
if (!good) {
return allResults;
}
could change to say,
if (!good)
{
if (processAllItems)
{
break;
}
else
{
return allResults;
}
}
I've changed the source to do the break and everything works as I would like
it to. Unfortunately my shop won't allow me to make this change for our
project, but it you guys make the change and release I can use it.
Thanks,
Ed
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org