• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

validation in struts2

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
1. When I try to validate the form parameters in struts2 for "required" validation, all the other messages that are associated with the field are also being displayed.For ex:
<field name="empid">
<field-validator type="required">
<message>Emp id is required</message>
</field-validator>
<field-validator type="regex">
<param name="expression"><![CDATA[^\d*$]]></param>
<message>Employee ID should be a number</message>
</field-validator>
<field-validator type="regex">
<param name="expression">^[1-9]\d*$</param>
<message>Employee ID cannot begin with a zero</message>
</field-validator>
</field>

In the above case, empid is an integer, when I do not specify any id and submit the form,all the above messages are displayed.How do I avoid this.

2.I ahve used the following pattern in validation.xml file for password and confrm password matching:
<validator type="expression">
<param name="expression">
password eq password2
</param>
<message>Confirm password should be same as password.</message>
</validator>
But there is no effect when I submit the form with differenct passwords.

Also, tried to use the following in action class but in vain:
@FieldExpressionValidator(expression = "(password == password2)", fieldName = "password2", message = "Passwords must match.")
Could you someone help me for the above two scenarios.

Thanks in advance.
 
Ranch Hand
Posts: 1211
Mac IntelliJ IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For 1, use Short Circuiting Validator.
 
reply
    Bookmark Topic Watch Topic
  • New Topic