• 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

Controlling Struts Validation Dynamically

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have some fields on a form which "might" need to be validated. Eg: When radio button 1 is chose, then validate field 1, ignore field 2. When radio button 2 is chose, then validate field 2, ignore field 1.
Thus, this is a bit contradicting with the common validation which struts provide, ie: if field 1 validation flag is set to true, then validation would always take place.
This become worst as I am using the struts javascript validation - <html:javascript> tag, which would generate the javascript for validation during runtime.
So, is there anyway for me to enable field validation dynamically instead of hard-coding.
Perhaps, writing my own javascript for those field is the easiest way but then the internationalization problem would pop up because error message is not taken from the ApplicationResources.properties anymore.
Please advice.
Thanks in advance.
 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Perhaps, writing my own javascript for those field is the easiest way but then the internationalization problem would pop up because error message is not taken from the ApplicationResources.properties anymore


What I am suggesting is a kludge but may work in your case. You could have the error message as a property in your Bean class and read it in in your JSP file within your javascript function like this.

A nicer alternative would be to put your own conditional Javascript validation in the validator-rules.xml
 
James Gordon
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ravi,
Thanks four your reply.
The method of storing error message to a javascript variable is fine but I can't really find a way to pass in the argument (arg0), unless it is hard-coded.
What is in my ApplicationResources is something like this (actually I use bean:message):
errors.required={0} is mandatory.
testmodule.label=Field 1
<bean:message key="errors.required" arg0={Should Pass In testmodule.label}/>
Unless I can store the <bean:message> value to a JSP variable, else I can't see anyway to pass in the value for arg0.
Any help would be greatly appreciated.
Thanks in advance.
reply
    Bookmark Topic Watch Topic
  • New Topic