Announcement Announcement Module
No announcement yet.
BeanValidator ignored Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • BeanValidator ignored

    I am having trouble getting the bean validator to work. Right now, nothing is validated. Maybe its not loading the validator.xml. How can I verify?

    Here's the config.

    <bean id="beanValidator" class="org.springmodules.validation.bean.BeanValid ator">
    <property name="configurationLoader" ref="configurationLoader"/>

    <bean id="configurationLoader" class="org.springmodules.validation.bean.conf.load er.xml.DefaultXmlBeanValidationConfigurationLoader ">
    <property name="resource" value="classpath:/validation/validation.xml"/>
    <property name="elementHandlerRegistry" ref="handlerRegistry"/>

    And of course, the validation.xml
    <form name="feeSetup" >
    <field property="fee.type" depends="required" >
    <arg key="error.required" />

  • #2
    Have you set validator/validators on your form controller? Post that xml config.

    One way to verify is turn on the logging for spring! It will tell you what's loaded and what's going on as you run the webapp.


    • #3
      of course, 2 days of searching is the equivalent to posting a question and then searching about 10 minutes longer. Found the problem. Apparently, we have two validation.xml files in this project. Only one is loaded. Guess which one I was editing. If you hear about some guy in a clock tower with a high powered rifle in Atlanta, GA, that would be me.


      • #4
        Just to help other people who might run into a similar problem, it is important to understand that just putting the BeanValidator on the app context doesn't automatically cause validation to happen. You have to inject your BeanValidator into whatever component is going to actually use it (whether that's a controller or even a component further back such as a service bean or even a DAO) and explicitly invoke its validate() method.

        My understanding is that in Spring 3 there will be tighter integration between Spring Web MVC and Hibernate Validator (possibly Bean Validation Framework as well but it didn't sound like that was a definite). I believe that one aspect of the tighter integration would be that you don't have to invoke validation methods explicitly from the controller. That's at least what I understood when I heard it; I guess we'll find out soon enough. :-)