Announcement Announcement Module
No announcement yet.
Spring and commons validation Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring and commons validation

    I set up a form extending a simpleFormController to work with a Validator ( with much help received from this forum).
    Everything worked fine - trapping errors and displaying them on the jsp page. However this was done using springs validation framework.
    I was now trying to get validation with commons-validation working but it fails on few things.
    I'm aware that spring modules is another project which is currently under work and does include integration with commons-validation. Since there is not much documentation , it's a little bit of a struggle. So i turn to the one place i've got results every single time - the forum

    This is what i have in my app-servlet.xml

    <bean id="validatorFactory" class="org.springmodules.commons.validator.DefaultValidatorFactory">
            <property name="validationConfigLocations">
        <bean id="beanValidator" class="org.springmodules.commons.validator.DefaultBeanValidator">
            <property name="validatorFactory"><ref local="validatorFactory"/></property>
    I stumbled upon a few pages on Matt Raible's blog about integrating commons-validation with spring. But the code in his examples follow a different API. I came to the conclusion that since it was written sometime in 2004, that it has changed and is re-organized and refactored differently under spring modules.
    Here is the xml for my controller -
    <bean name="/secured/tradeEntry.frm" class="">
    		<property name="mvcMap">
                    <entry key="name" value="trade_entry"/>
                    <entry key="permission" value="SCREEN_ACCESS"/>
                    <entry key="page" value="/secured/trade_entry.jsp"/>
                    <entry key="url" value="/secured/tradeEntry.frm"/>
            <property name="validator" ref="beanValidator"/>
            <property name="commandName" value="smtmTradeMessage"/>
            <property name="commandClass" value=""/>
            <property name="formView" value="/secured/trade_entry.jsp"/>
            <property name="successView" value="/secured/trade_entry_review.jsp"/>

    Initializiation of the "/secured/tradeEntry.frm" bean fails because it says that the validator does not support the command class. What makes a command class "supportable" to a validator? what am i doing wrong?

    The above configuration works fine when i use spring's own validation.
    Any help will be appreciated. Thank you.

  • #2
    If you use the library out-of-the-box, in your config for Commons Validator the name of each form has to be the short name of your command class, so in your case that would be smtmTradeMessage.


         <form name="smtmTradeMessage">


    • #3
      Works. Thanks

      Cuong, Thank you. That was what it was.


      • #4

        Well, i ran into a hurdle trying to get the application read values off of
        I tried putting it under /web-inf/, and also under the root.
        And in my web.xml i tried -

        Both of the above additions to web.xml didn't get Spring to read values from the properties file. What am i doing wrong?..or what am i not doing?
        Thanks in advance.


        • #5
          The errors being generated are Spring's FieldError objects which resolve their messages from MessageSource beans rather than the 'Struts' way.

          Here's the doc:

          So, I suppose you could just add ApplicationResources to the list of resource bundles.

          Hope that helps,



          • #6
            Worked, thanks.

            Cuong, thanks again.That solved it.


            • #7
              Server side also

              It might be a stupid thing to ask, but is common-validators from springmodules supposed to validate on the server side also, when JavaScript is not an option ? I have it configured and working on the client side (JavaScript) but when I disable JavaScript it doesn't seem to validate.

              I'm not sure if it is an issue, but I have 2 validators for this SimpleFormController extender, the first one is the commons-validator , the other is a normal spring validator.