Announcement Announcement Module
Collapse
No announcement yet.
Problems with spring commons validator integration Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problems with spring commons validator integration

    I've been attempting to add support for commons validator to my application following Matt's Spring Live examples. Everything was going smoothly until I tried to get the client side javascript validation going (server side works).

    Using the Spring Live examples I've created a validator.jsp with the following content:
    Code:
    <%@ page language="java" contentType="javascript/x-javascript" %>
    <%@ taglib uri="http&#58;//www.springframework.org/tags/commons-validator" prefix="html" %>
    <html&#58;javascript dynamicJavascript="false" staticJavascript="true"/>
    And in my maintenance-servlet.xml I have defined the ValidatorFactory:
    Code:
    <bean id="validatorFactory" class="org.springframework.validation.commons.DefaultValidatorFactory" init-method="init">
        <property name="resources">
            <list>
                <value>/WEB-INF/validator-rules.xml</value>
                <value>/WEB-INF/validation.xml</value>
            </list>
        </property>
    </bean>
    When this page gets invoked an exception is thrown with the message:
    org.springframework.beans.factory.NoSuchBeanDefini tionException: No unique bean of type [org.springframework.validation.commons.ValidatorFa ctory] is defined: Expected single bean but found 0
    I've been looking at the code for the spring commons validator tag and the getValidatorResources() method tried to first get the WebApplicationContext using the following code:
    Code:
    WebApplicationContext ctx = 
        &#40;WebApplicationContext&#41;   pageContext.getRequest&#40;&#41;.getAttribute&#40;
            DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE
        &#41;;
    Then falls back to:
    Code:
    ctx = WebApplicationContextUtils.getRequiredWebApplicationContext&#40;
        pageContext.getServletContext&#40;&#41;
    &#41;;
    Because the WebApplicationContext can't be found with the first call the main context is loaded from the fall back code. The ValidatorFactory isn't defined there so the NoSuchBeanDefinitionException is thrown.

    I must have missed something... Does anyone have any ideas on how to resolve this?

    Cheers,
    Dan

  • #2
    Doh! To answer my own question, Matt has the ValidatorFactory loaded into the main context.

    *sigh*

    Comment


    • #3
      What does this mean tho?

      So I have the same issue but am still trying to figure out what this means??

      What's the main context? Are you referring to the App context? Well, digging I will go.. If I figure this out, I'll post back.

      Comment

      Working...
      X