Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Struts
Search Coderanch
Advance search
Google search
Register / Login
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
Tim Cooke
Liutauras Vilda
Jeanne Boyarsky
paul wheaton
Sheriffs:
Ron McLeod
Devaka Cooray
Henry Wong
Saloon Keepers:
Tim Holloway
Stephan van Hulst
Carey Brown
Tim Moores
Mikalai Zaikin
Bartenders:
Frits Walraven
Forum:
Struts
validation of arrays using validator.xml
Deepak vellore
Greenhorn
Posts: 5
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
hi, i want to validate form properties which are of type arrays , how can i validate the same.
SCJP 5.0
Ud Naik
Greenhorn
Posts: 18
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Dont know if this fits your requirement, but it's worth a try
1) Write a class that does the validation for you:
package package.blahblah; import necessary stuff; public class [B]ArrayFieldsValidator[/B] { public static boolean [B]validateArrayFields[/B](Object bean, ValidatorAction va, Field field, ActionMessages errors, Validator validator,HttpServletRequest request) { String[] firstValue = ValidatorUtils.getValueAsString(bean, field.getProperty()); String[] secondValue = ValidatorUtils.getValueAsString(bean, field.getVarValue("[B]compareWith[/B]"));; /* Do the restof the validation here */ }
2) Add a new validator to validation-rules.xml with the above class as the validator
<validator name="[B]arrayFieldsValidate[/B]" classname="package.blahblah.[B]ArrayFieldsValidator[/B]" method="[B]validateArrayFields[/B]" methodParams="java.lang.Object, org.apache.commons.validator.ValidatorAction, org.apache.commons.validator.Field, org.apache.struts.action.ActionMessages, org.apache.commons.validator.Validator, javax.servlet.http.HttpServletRequest" depends="" msg="[B]errors.arrayFieldsNotMatch[/B]"/>
3) Use this validator in validation.xml
<form name="myArrayForm"> <field property="arrayField" depends="required,[B]arrayFieldsValidate[/B]"> <arg0 key="yourChoice"/> <arg1 key="oneMoreChoice"/> <var> <var-name>[B]compareWith[/B]</var-name> <var-value>anotherArrayField</var-value> </var> </field>
Hope this has been clear. Good luck.
I am Arthur, King of the Britons. And this is a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
indexedListProperty for long arrays
Threads and Clonning
Simple variable initialization ques
How could I print names randomly?
jQuery Galleria Photogallery problem in quirks mode
More...