• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Controlling Struts Validation Dynamically

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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.
 
Sometimes you feel like a nut. Sometimes you feel like a tiny ad.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic