If you want to print out a specific message for the validation, you can
add that to the field, too:
<field property="username" depends="required,minlength">
<arg key="username"/>
<var><var-name>minlength</var-name><var-value>6</var-value></var>
<msg name="minlength" key="The minimum length for the User Name is
6" resource="false" />
</field>
David Duff <[EMAIL PROTECTED]>
08/24/2005 12:09 PM
Please respond to
"Jakarta Commons Users List" <[email protected]>
To
Jakarta Commons Users List <[email protected]>
cc
Subject
Re: Commons Validator problem
Hi,
Thanks for the reply
The msg I want to print out has two arguments:
errors.min=The {0} must have at least {1} characters.
This would leave:
The user name must have at least {1} characters.
I can get round the problem I'm having by specifying a value in the
resource like
<field property="username" depends="required,minlength">
<arg key="user.username" position="0"/>
<arg key="user.min" position="1"/>
<var><var-name>minlength</var-name><var-value>6</var-value></var>
</field>
properties file:
user.min= 6
I would like to do it like it was specified in the user guides instead
of intoducing a workaround and having to input the value twice. Once in
the resource and another in the validator.xml.
Thanks in advance.
David
Aaron Sheffey wrote:
>You probably don't need to specify all the other stuff in the field.
Based
>on what I have done with mask, do something like
>
><field property="username" depends="required,minlength">
> <arg key="username"/>
> <var><var-name>minlength</var-name><var-value>6</var-value></var>
></field>
>
>
>
>
>David Duff <[EMAIL PROTECTED]>
>08/24/2005 11:43 AM
>Please respond to
>"Jakarta Commons Users List" <[email protected]>
>
>
>To
>[email protected]
>cc
>
>Subject
>Commons Validator problem
>
>
>
>
>
>
>Hi,
>
>I am trying to specify a min. length for a user name field in my
>application.
>
>In my validatior.xml I have specified:
>
>|<field property="username" depends="required,minlength">
> <arg key="user.username" position="0"/>
> <arg name="minlength" key="${var:minlength}" resource="false" ||
>position="1"||/>
> <var><var-name>minlength</var-name><var-value>6</var-value></var>
></field>
>
>In my validator-rules.xml I have:
>
><validator
> name="minlength"
>classname="com.company.product.controller.validator.CustomValidator"
> method="validateMinLength"
> methodParams="java.lang.Object,
> org.apache.commons.validator.Field"
> msg="errors.min"/>
>
>In my custom validator I have my validateMinLength() method.
>
>I would expect the two arguments (user.username and minlength) to get
>picked up but it only picks up the first argument even though ||I can
>see the two args in the field object||. When I remove the name
>attribute from arg, it will then pick up the second argument but look
>for the key in the resource even although resource is set to false.
>
>I am using commons-validator-1.1.4.jar|
>
>Can anyone tell me what I'm doing wrong?
>
>Thanks in advance.
>David
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
>
>
>------------------------------------------------------------------------
>
>No virus found in this incoming message.
>Checked by AVG Anti-Virus.
>Version: 7.0.338 / Virus Database: 267.10.15/80 - Release Date:
23/08/2005
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]