[Validator] Validation sous condition !
Bonjour,
J'ai un objet A qui contient un attribut ab
Cet attribut est un numérique à 10 chiffres (obligatoirement), et je voudrais le tester à l'aide d'un validator sous la condition que l'objet A existe (car il est possible dans mon formulaire que A n'existe pas !)
J'ai donc fait un validator qui ressemble à cela :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| <form name="monForm">
<field property="A.ab" depends="validwhen,minlength,maxlength,integer">
<arg0 name="minlength" key="${var:minlength}" resource="false"/>
<arg1 name="maxlength" key="${var:maxlength}" resource="false"/>
<var>
<var-name>test</var-name>
<var-value>(A != null)</var-value>
</var>
<var>
<var-name>minlength</var-name>
<var-value>10</var-value>
</var>
<var>
<var-name>maxlength</var-name>
<var-value>10</var-value>
</var>
</field>
</form> |
Seulement ca ne fonctionne pas !, et j'ai une erreur qui ressemble à ceci :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| ValidatorAction.java executeValidationMethod 579 [09:48:45] [ERROR] Unhandled exception thrown during validation: Null property value for 'A'
org.apache.commons.beanutils.NestedNullException: Null property value for 'A'
at org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:669)
at org.apache.commons.beanutils.PropertyUtilsBean.getProperty(PropertyUtilsBean.java:715)
at org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:290)
at org.apache.commons.validator.util.ValidatorUtils.getValueAsString(ValidatorUtils.java:102)
at org.apache.struts.validator.validwhen.ValidWhen.validateValidWhen(ValidWhen.java:103)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.commons.validator.ValidatorAction.executeValidationMethod(ValidatorAction.java:544)
at org.apache.commons.validator.Field.validateForRule(Field.java:796)
at org.apache.commons.validator.Field.validate(Field.java:876)
at org.apache.commons.validator.Form.validate(Form.java:288)
at org.apache.commons.validator.Validator.validate(Validator.java:351)
at org.apache.struts.validator.ValidatorForm.validate(ValidatorForm.java:116) |
Alors est ce que j'ai une mauvaise syntaxe, une mauvaise méthode, ou pire, que ce que je cherche à faire n'est pas possible...
Merci d'avance de votre aide !