Announcement Announcement Module
Collapse
No announcement yet.
How to configure Validation in MultiActionController Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to configure Validation in MultiActionController

    Hi when i try to use MultiActionController to validate i received a error can anyone help me

    My code is
    Controller

    Code:
    public class SampleViewController extends MultiActionController  {
    
    public ModelAndView createUser(HttpServletRequest request, HttpServletResponse response, User command){
    		System.out.println(getCommandName(command));
    		if(command.getFirstname()==null){
    			return new ModelAndView("home","command",command);
    		}
    		System.out.println("Create User");
    		//User u=(User)command;
    		System.out.println("Value is "+command.getFirstname());
    		System.out.println("Value is"+command.getLastname());
    		return new ModelAndView("success","command",command);
    	}
    Validatior class

    Code:
    public class MultiactionValidatorSample implements Validator {
    	public boolean supports(Class clazz) {
    		return clazz.equals(User.class);
    	}
    	
    	public void validate(Object command, Errors errors){
    		User u=(User)command;
    ValidationUtils.rejectIfEmpty(errors,"firstname","required.firstname","First Name is Required");
    	}
    }
    DispatchServlet

    Code:
    <bean name="/sample.html" class="com.percipient.controller.SampleViewController">
        <property name="methodNameResolver">
            <bean class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver">
                <property name="paramName" value="method"/>
            </bean>
        </property>
    	<property name="validators">
    			<bean				class="com.percipient.validator.MultiactionValidatorSample" />
    	</property>
    	</bean>
    When i try to run i get the error

    Code:
    org.springframework.web.bind.ServletRequestBindingException: Errors binding onto object 'command'; nested exception is org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
    Field error in object 'command' on field 'firstname': rejected value [null]; codes [required.firstname.command.firstname,required.firstname.firstname,required.firstname.java.lang.String,required.firstname]; arguments []; default message [First Name is Required]
    	org.springframework.web.bind.ServletRequestDataBinder.closeNoCatch(ServletRequestDataBinder.java:121)
    	org.springframework.web.servlet.mvc.multiaction.MultiActionController.bind(MultiActionController.java:541)
    	org.springframework.web.servlet.mvc.multiaction.MultiActionController.invokeNamedMethod(MultiActionController.java:470)
    	org.springframework.web.servlet.mvc.multiaction.MultiActionController.handleRequestInternal(MultiActionController.java:410)
    	org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
    	org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
    	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
    	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809)
    	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:476)
    	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:431)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

  • #2
    It's not really clear that this is a problem. Are you saying this is happening even if you are specifying a first name?

    Comment


    • #3
      When i tried to removed the vaildators property in dispatch servlet its working fine, the value of the firstname get in the controller class

      if there is any sample program or documentation for validation with multiactioncontroller please send me

      Comment


      • #4
        remove <sprin:bind> from your Jsp page.and error resolved

        Comment


        • #5
          Did this problem get resolved, i am getting the same problem

          Comment


          • #6
            Hi,

            If you use validator property, then multiaction controller(Java class) must have validator property.But setValidator method is available from Base Command Controller. Anyway multiAction controller is not an sub class of Command controller. Because of that you cant declare property called "validators" in your xml file.

            Comment

            Working...
            X