• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Multiple field validation in Struts2 Validation using validation.xml file

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Empty form fields aren't null, they're empty strings.
 
Rajesh Kumar Prabhakaran
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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>

 
Surfs up space ponies, I'm making gravy without this lumpy, tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic