Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

validation particular fields for different actions in a single page

 
Swathi Prakash
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,

pls help me...

i have page with 5 fields...and two buttons... for the first button i need only 2 fields required . for second button i need all fields required...how to do in struts???for these 2 buttons i m calling the same action..



from the first button action i will get the value of third field value.. then i want to submit the second button where i required all fields...

how to use validation of struts for these conditions... i m using only one form for this page...please help me.....


SWATHI
 
David Ulicny
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im not sure how to do this within struts, but you can use different javascript validation functions for each button.
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can check which button was click from within your ActionForm's validate method.
 
alan do
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you are using declarative validation, name both buttons the same 'name' (ex. 'submitButton'), but specify different values for each (ex. 'Update', 'Add'). in your validation.xml, use the 'validwhen' rule to check the 'submitAction' value together with the required fields if you are using struts 1.2.x (see the struts user guide). use 'requiredif' to do the same if you are using struts 1.1.x. follow marc's suggestion if you are using struts 1.0.x.
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by alan do:
follow marc's suggestion if you are using struts 1.0.x.


... or if you aren't using declarative validation in any version of Struts.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic