• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

Struts 2: conditional validation, how to do that?

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
I am new to Struts 2. I have a form with 2 fields, last name and id. If somebody wants to search the data from the Database by either one of the field, they can enter only one field.I wrote a search-validation.xml with both the fields as required string. In the action class, i am checking if both of them are null, go to input page, otherwise, go to the success page.
On deployment, if I miss one of the fields, it still gives me a field is required message.
Is there anything I should do with the validation.xml file to fix this?
The other option I have is write two forms with 2 actions and 2 validation.xml files. Is that the best route?
P.S: I was checking struts validation and in struts 1.2, they have conditional validation. Could I use that or something like that in Struts 2
Thanks in advance
Vidya
[ August 08, 2008: Message edited by: Vidya Moorthy ]
 
Ranch Hand
Posts: 83
Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First Point :
Well if this is what you wrote in Action class


then you are using wrong operator in if condition, you are using a single & which is used for bitwise AND condition, which is not what you want.

You need to use boolean AND operator here which is ==> &&

Second Point

you will still have to write a custom validation for this type of scenario.
If you are using client side validation then you can do it using simple java ascript function

Let me know if you need help on JavaScript code....

Hope this helps....
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could also overwrite the ActionSupport class's validate method and create custom required validate methods to do this.

http://www.opensymphony.com/xwork/api/com/opensymphony/xwork/ActionSupport.html
[ August 11, 2008: Message edited by: Charles Z Martin ]
 
I miss the old days when I would think up a sinister scheme for world domination and you would show a little emotional support. So just look at this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!