Java Mailing List Archive

http://www.gg3721.com/

Home » Struts Users Mailing List »

[Help]: Struts2 List object validation

张云勇

2008-11-24

Replies: Find Java Web Hosting

Author LoginPost Reply

Now I suffer a problem with s2' validation.

Here is my problem:

In my action,there is a property

List<Peson> persons;

now in jsp, I use iterator like below:
<s:iterator  value= "persons "  status= "stat ">
  <s:textfield  label= "%{ 'Person  '+#stat.index+ '  Name '} " name=
"%{ 'persons[ '+#stat.index+ '].name '} "  />
  <s:textfield  label= "%{ 'Person  '+#stat.index+ '  Age '} "  name=
"%{ 'persons[ '+#stat.index+ '].age '} "  />
</s:iterator>

I want to validation user input while submit the form, “name" should not
empty, and "age" must be number.

in my validation config file I write like this:
<validators>
  <field name="persons[].name">
    <field-validator type="requiredstring">
       <message key="requiredstring" />
    </field-validator>
  </field>
  <field name="persons[].age">
    <field-validator type="short">
       <message key="requiredshort" />
    </field-validator>
  </field>
</validators>

It seems doesn't work.


Besides that, I want to add error style to the filed which doesn't pass the
validation. In S1,we can use
<html:text errorStyle="errorStyle" .../>
to achieve this task, but How to do it in S2?
--
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 gg3721.com - Jax Systems, LLC, U.S.A.