aspose file tools *
The moose likes Struts and the fly likes validation in struts2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "validation in struts2" Watch "validation in struts2" New topic
Author

validation in struts2

Rajani Panchumarthy
Greenhorn

Joined: Jan 27, 2009
Posts: 22
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

Joined: Feb 02, 2002
Posts: 1211

For 1, use Short Circuiting Validator.


The future is here. It's just not evenly distributed yet. - William Gibson
Consultant @ Xebia. Sonny Gill Tweets
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: validation in struts2