• 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

Skipping validation on fields that are not part of the rendered form

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a form that is built dynamically based on a company profile.
When the form is rendered some of the fields are not rendered because of the profile settings.
This is accomplished using struts2 if statements.

So...when the form is submitted for validation...how can I "skip" the validation for fields that do not exist in the form but have validation rules in validation.xml?

Is there a way to say "if field exists then validate else skip" from within the validation rules?


 
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
Welcome to the JavaRanch. Off the top of my head, there are two options:
One, you could have the action the form is submitted to be profile-specific. That would let you keep the validation in the "usual" place: the XML files.
Two, it is also possible to implement ValidationAware by providing your own validate method (if you use ActionSupport as your Action's base class, note that it already implements ValidationAware).
Personally, I find it easier to handle logic in code than in configuration files, so I tend to override validate if my requirements are more than simple field checks. Some people may find that confusing if they expect all validation logic to be in the XML files.
reply
    Bookmark Topic Watch Topic
  • New Topic