Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

validation in struts2

 
Rajani Panchumarthy
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • 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.
 
Sonny Gill
Ranch Hand
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For 1, use Short Circuiting Validator.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic