aspose file tools*
The moose likes Struts and the fly likes Multiple field validation in Struts2 Validation using validation.xml file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Multiple field validation in Struts2 Validation using validation.xml file" Watch "Multiple field validation in Struts2 Validation using validation.xml file" New topic
Author

Multiple field validation in Struts2 Validation using validation.xml file

Rajesh Kumar Prabhakaran
Greenhorn

Joined: Sep 08, 2010
Posts: 2
Hi,

My requirement is, I have 3 fields in a jsp and I should throw an error message if all the 3 fields are null or empty. If anyone of the field is NOT NULL, then it should NOT throw an error. I'm using Struts 2 validation framework with validation.xml file. I need to do it as a client side validation. I tried the following code but its not working. Can anyone please send a sample code to make this run.

I tried:

<field name="searchdata.lastName">
<field-validator type="fieldexpression">
<param name="expression">
((searchdata.lastName)==null) and ((searchdata.policyNumber)==null) and ((searchdata.policyDate)==null)
</param>
<message>Enter Last Name or Policy Number or Policy Date.</message>
</field-validator>
</field>
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Empty form fields aren't null, they're empty strings.
Rajesh Kumar Prabhakaran
Greenhorn

Joined: Sep 08, 2010
Posts: 2
Even I tried with EMPTY STRING.

((searchdata.lastName)=="") and ((searchdata.policyNumber)=="") and ((searchdata.policyDate)=="")

But still its not working for me. Any sample code will be helpful.

Thanks & Regards,
Rajesh.
suraj savaratkar
Ranch Hand

Joined: May 17, 2010
Posts: 60

You can see more syntax in workx2 in library files

<field name="firstname"> it shoud be same as your jsp property name
<field-validator type="requiredstring"> check for empty text
<message>Your message</message> write your message to appear in jsp
</field-validator>
</field>

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multiple field validation in Struts2 Validation using validation.xml file
 
Similar Threads
Visitor Validator with a variable context
Invalid field value for field "Date"
Conditional validation in Struts2
Struts2:Conditional visitor validator not conditional
Struts 2 visitor validation not able to get any error message