• 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

struts 2: custom java validation?

 
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You’ll find me in my office. I’ll probably be drinking. And reading this tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic