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

Struts2 Conditional Validation or serverside fieldpopulation before validation

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Im having some difficulties finding a suitable way to solve my little problem.
I have a form with several fields. This form is validated by several inhouse-built customvalidators and are executed by @Validations annotation on the update() metode of our action class.
Now we are introducing a new radiobutton, and when this radiobutton is set to a specific value there should be no validation of 6 fields in our form.
This seemed quite straight forward, but now im stuck.
Can this problem be easily solved within the annotations? Is there some way to tell the validators not to validate if radiobutton is set to specific value within the annotation?
I couldnt find a way, so i tried a different solution.

My next idea was that I could do an if statement within the prepare() metode. I'll do a check within the prepare, and if the radiobutton is set to no-validation, then i would simply populate the fields myself with some default-values that i knew would validate.
Ok, that should work i though, but the validation still failed. After debugging i found that the values i had set in the prepare() somehow had dissappeared when the customvalidators did their validation. I mean the fields i specificly set to a value in the prepare metode are set back to the values from the form before validation is run.

hmm...
I'm running out of ideas. Any Struts2 validation gurus have some tips?

Thanks guys!!
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not a guru, but whenever I have a validation that's more complicated than the bundled validators, I override ActionSupport.validate (all my actions extend ActionSupport) and do the validation there.
 
Message for you sir! I think it is a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic