Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Struts 2 »

Struts 2 Validation multiple validators on same field

orshoe

2007-08-07

Replies:


Hi all,
I am trying to enforce a "requiredstring" on a text field and also make sure
it follows certain constraints. I am using the following in the
<action>-validation.xml:
---------------------------------------------------------------------------------------------------------------------------
<validators>
  <field name="accountNumber">
    <field-validator type="int">
        <para m nam e="min">6</para m>
        <para m nam e="max">10</para m>
       <message>Account Number cannot be less than ${min} or greater
than ${max}. Its currently ${accountNumber}</message>
    </field-validator>
  </field>
  <field name="accountNumber">
    <field-validator type="requiredstring">
       <message>You must enter Account Number</message>
    </field-validator>
  </field>
</validators>
---------------------------------------------------------------------------------------------------------------------------
The problem is, I am getting both the messages displayed (also the "You must
enter Account Number") even when there is a value (say, 5) entered in the
field. Is there any way to get only the appropriate message displayed based
on the input.
note: Please ignore the extra spaces in the param tags, I had intentionally
added the space to make sure the message preview'd properly.
--
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@(protected)
For additional commands, e-mail: user-help@(protected)

©2008 junlu.com - Jax Systems, LLC, U.S.A.