Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

struts 2: custom java validation?

 
Chris Boldon
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings,

I have recently started using Struts 2 and am starting to port some of my old Struts applications over.

One of my application has some complex validation code that makes database calls to see if values are already present, etc.

Is there a way to utilitze the Struts 2 validation framework to do this? Or do I have to do the old school way and forward to different results in an if loop based on certain results?

Thanks in advance.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what you're looking for--you can write custom Java validators in S2, or use the validate() method. If you have complicated logic that needs to return to a page other than the INPUT result it'll require more work.
 
Chris Boldon
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess I am looking for a way to implement custom validation that will be inspected at the same time as annotation and xml-validator validation.

the validate() method runs at a different priority from my experience.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then you'd implement a custom validator, much the same way as in S1. It might be more straight-forward to implement it in a validate() method, however.

As far as the different "priority", just like with S1, you can call super.validate() inside the validate() method, so that the DB-based validation is run immediately after the XML/annotation-based validation, which I'd assume is what you'd want anyway.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic