Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring commons-validator issue IlleagalArgumentException

 
murali kankanala
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I am trying to use commons-validator framework for validation in Spring MVC. i am getting following exception.

java.lang.IllegalArgumentException: Validator [org.springmodules.commons.validator.DefaultBeanValidator@1d5b945] does not support command class [com.training.springmvc.Details]


I have attached code in zip file. Could you please help me to resolve the issue.
 
murali kankanala
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also pasting the code.

Controller



Command



application context xml



validation.xml

 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would start with using the annotation based controllers which is the accepted way do controllers since Spring 2.5. There should not be a need to extend SimpleFormController. If you are using newer versions of Spring they have full support for the JSR303 Bean validation API. You can use these and just add hibernate-validator to your classpath.

See the reference documentation
http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/validation.html#validation-beanvalidation
 
murali kankanala
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But i am using spring 2.0 in my project, so i need a solution with common-validator only.
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The name of your command class must match the "name" attribute in yourform definition in validation.xml. If this is unacceptable you can look at using ConfigurableBeanValidator instead of DefaultBeanValidator.

http://www.springbyexample.org/maven/site/org.springbyexample.validation/0.94/apidocs/org/springmodules/validation/commons/ConfigurableBeanValidator.html

 
murali kankanala
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are right , i was assuming , in the below code i have set "user" as form name what being used in jsp to read from request scope. Usually in struts we assume this is the name that we have to use in validation.xml. Hmm but in spring it is different.



Now what i understand is below



 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic