Posted By:
java_doe
Posted On:
Monday, February 27, 2012 04:59 PM
How to correctly use alternate messages in the Struts validation framework. Based on the following information from Programming Jakarta Struts Chapter 11 The Validator Framework http://books.google.com/books?id=E874l0jaUGQC&pg=PA260&lpg=PA260&dq=change+the+key+values+in+the+validation-rules.xml+if+you+plan+to+use+alternative+messages&source=bl&ots=t5zzY8fSs4&sig=wEOspEiq8XsU2su4yD1WlCz8H6w&hl=en&sa=X&ei=8_ZLT6TOHoPi0QGB4YiTDg&ved=0CCIQ6AEwAA#v=onepage&q=change%20the%20key%20values%20in%20the%20validation-rules.xml%20if%20you%20plan%20to%20use%20alternative%20messages&f=false You should add these to your applications resource bundle, or change the key values in
More>>
How to correctly use alternate messages in the Struts validation framework.
Based on the following information from Programming Jakarta Struts
Chapter 11 The Validator Framework
http://books.google.com/books?id=E874l0jaUGQC&pg=PA260&lpg=PA260&dq=change+the+key+values+in+the+validation-rules.xml+if+you+plan+to+use+alternative+messages&source=bl&ots=t5zzY8fSs4&sig=wEOspEiq8XsU2su4yD1WlCz8H6w&hl=en&sa=X&ei=8_ZLT6TOHoPi0QGB4YiTDg&ved=0CCIQ6AEwAA#v=onepage&q=change%20the%20key%20values%20in%20the%20validation-rules.xml%20if%20you%20plan%20to%20use%20alternative%20messages&f=false
You should add these to your applications resource bundle, or change the key values in the validation-rules.xml if you plan to use alternative messages.
I have the following code in validator-rules.xml file.
classname="StrutsValidators"
method="validateRequired"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionMessages,
javax.servlet.http.HttpServletRequest"
msg="errors.required.new"/>
classname=" StrutsValidators"
method="validateMask"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionMessages,
javax.servlet.http.HttpServletRequest"
depends=""
msg="errors.invalid.new"/>
I added the following string to the properties file.
errors.required.new={0} is required NEW!!!
errors.invalid.new={0} is not valid NEW!!!.
My validation.xml file looks like this:
maxbytelength
32
form
Info
mask
^[0-9-() ]*$
I still see the standard error messages such as the ones listed below displayed on the UI.
errors.required.new={0} is required.
errors.invalid.new={0} is not valid.
Is this a Struts bug? If not, what is the right way to use alternate validation message in this case?
Thanks a lot.
<<Less