You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Maurice Hüllein <Ma...@Web.de> on 2006/02/20 17:23:21 UTC
[validator] Problems with method invokation for application validation
Im currently trying to use the Validator for my swing-application. Therefor
I modified a tutorial, so that those sources were created (shortened: no
exception etc):
validation source:
ValidatorResources resources = null;
File f = new File("validation.xml");
resources = new ValidatorResources(f.getAbsolutePath());
Validator validator = new Validator(resources, "plugin1");
Value v = new Value();
validator.setParameter(Validator.BEAN_PARAM, v);
ValidatorResults results = null;
results = validator.validate();
The Object "Value" is only my data carrier with two String named
textfield1 and
textfield2 with corresponding getters/setters.
the validation-xml shall only validate, that these fields are filled
with values ("required"):
<!DOCTYPE form-validation PUBLIC
"-//Apache Software Foundation//DTD Commons Validator Rules
Configuration 1.1//EN"
"http://jakarta.apache.org/commons/dtds/validator_1_1.dtd">
<form-validation>
<global>
<validator name="required"
classname="org.apache.struts.util.StrutsValidator"
method="validateRequired"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionErrors,
javax.servlet.http.HttpServletRequest"
msg="errors.required">
</validator>
</global>
<formset>
<form name="plugin1">
<field property="textfield1" depends="required">
<arg0 key="login.textfield1"/>
</field>
<field property="textfield2" depends="required">
<arg0 key="login.textfield2"/>
</field>
</form>
</formset>
</form-validation>
The problem is, that I get an Exception at "results =
validator.validate();" which is:
org.apache.commons.validator.ValidatorException:
org.apache.struts.util.StrutsValidator
at
org.apache.commons.validator.ValidatorAction.loadValidationClass(ValidatorAction.java:623)
at
org.apache.commons.validator.ValidatorAction.executeValidationMethod(ValidatorAction.java:531)
at org.apache.commons.validator.Field.validateForRule(Field.java:766)
at org.apache.commons.validator.Field.validate(Field.java:845)
at org.apache.commons.validator.Form.validate(Form.java:290)
at org.apache.commons.validator.Validator.validate(Validator.java:353)
at ValidatorTest.validate(ValidatorTest.java:55)
at ValidatorTest.main(ValidatorTest.java:150)
I think my fault is to use the "methodParams" which are provided for web
interfaces and jsp.
But how can i use the standard validators (like required) for my plain
value object or single
values?
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org