Announcement Announcement Module
Collapse
No announcement yet.
need help with Commons Validator Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • need help with Commons Validator

    Somehow I don't get my commons validator to work after I changed my command class.

    I get following error message:

    Code:
    java.lang.IllegalArgumentException: Validator [org.springframework.validation.commons.BeanValidator@1ba5016] does not support command class [example.web.commandObj.UserFormCommand]
    validation.xml:
    Code:
    <form-validation>
    	<formset> 
    		<form name="user"> 
    			<field property="username" depends="required"> 
    				<arg0 key="user.user.username"/> 
    			</field> 
    		</form>
    	</formset> 
    </form-validation>
    action-servlet.xml:
    Code:
    <bean id="userFormController" class="example.web.UserFormController"> 
    		<!--  optional - if you don't define it then the default name is command -->
    		<property name="commandName">
    			<value>user</value>
    		</property> 
    		<property name="commandClass"> 
    			<value>example.web.commandObj.UserFormCommand</value> 
    		</property> 
    		<property name="formView">
    			<value>userForm</value>
    		</property> 
    		<property name="successView">
    			<value>showUser.html</value>
    		</property> 
    		<property name="userManager">
    			<ref bean="userManager"/>
    		</property> 
    		<property name="validator">
    			<ref bean="beanValidator"/>
    		</property>
    	</bean>

    the jsp file:

    Code:
    <form name="user" method="post" action="<c&#58;url value="/showAddUser.html"/>" onsubmit="return validateUser&#40;this&#41;"> 
    	<table> 
    		<tr> 
    			<th>
    				<fmt&#58;message key="user.username"/>&#58; 
    			</th> 
    			<td> 
    				
    				<spring&#58;bind path="user.user.username">
    	               <input type="text" name="$&#123;status.expression&#125;" value="<c&#58;out value="$&#123;status.value&#125;"/>">
    	               <span class="fieldError">$&#123;status.errorMessage&#125;</span>
    	            </spring&#58;bind>
    			</td>
    			&#91;...&#93;
    I already found a similar problem in the forum but I still haven't figured out what the problem is

  • #2
    It is likely that validation.xml is not used by the DefaultValidatorFactory or you are referencing an old version. Could you please double check that the referenced validation.xml file contains a definition for "user".
    HTH

    Comment


    • #3
      Originally posted by irbouho
      It is likely that validation.xml is not used by the DefaultValidatorFactory or you are referencing an old version. Could you please double check that the referenced validation.xml file contains a definition for "user".
      HTH
      I checked it ... and it is there and the validation.xml is the only version!

      <bean id="validatorFactory"
      class="org.springframework.validation.commons.Defa ultValidatorFactory" init-method="init">
      <property name="resources">
      <list>
      <value>/WEB-INF/validator-rules.xml</value>
      <value>/WEB-INF/validation.xml</value>
      </list>
      </property>
      </bean>

      Comment


      • #4
        Your form name in validation.xml should be "userFormCommand" rather than "user" to match your command class (but w/lowercase first letter.

        The C-V naming convention is pretty icky. <form> is actually referring to the classname, not the object name.

        HTH

        Comment

        Working...
        X