aspose file tools*
The moose likes Struts and the fly likes Struts2 Conditional Validation or serverside fieldpopulation before validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts2 Conditional Validation or serverside fieldpopulation before validation" Watch "Struts2 Conditional Validation or serverside fieldpopulation before validation" New topic
Author

Struts2 Conditional Validation or serverside fieldpopulation before validation

Arne Andersen
Greenhorn

Joined: Oct 02, 2008
Posts: 8
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!!
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8996
    
    9

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.


[How To Ask Questions On JavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts2 Conditional Validation or serverside fieldpopulation before validation