Results 1 to 4 of 4

Thread: BeanValidator ignored

  1. #1
    Join Date
    Sep 2008
    Posts
    4

    Question 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>

    <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"/>
    </bean>

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

  2. #2
    Join Date
    Jan 2007
    Location
    Orlando, FL USA
    Posts
    84

    Default

    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.
    http://www.jroller.com/thebugslayer - notes on java, scala and other development stuff.

  3. #3
    Join Date
    Sep 2008
    Posts
    4

    Default

    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. #4
    Join Date
    Jan 2005
    Location
    Phoenix, AZ
    Posts
    139

    Default

    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. :-)
    Willie Wheeler
    Author, Spring in Practice (Manning Publications)
    Spring stuff: Tutorials | Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •