Page 8 of 8 FirstFirst ... 678
Results 71 to 73 of 73

Thread: How to do validation using MultiActionController

  1. #71
    Join Date
    Jun 2011
    Posts
    1

    Default validation in multiaction controller

    Hi guys I have successfully implemented validation in multiaction controller .actually i have tweaked the bind method and defined bindObject method in a super class.BaseController which extends MultiactionController.

    protected BindException bindObject(HttpServletRequest request, Object command,
    Validator validator) throws Exception {
    ServletRequestDataBinder binder = createBinder(request, command);
    binder.bind(request);

    BindException errors = new BindException(command,getCommandName(command));
    if(validator.supports(command.getClass())){
    ValidationUtils.invokeValidator(validator, command, errors);
    }
    return errors;

    }



    and multiaction class extends this class and in any method for example authenticateUser method ---->

    public ModelAndView authenticateUser(HttpServletRequest request,
    HttpServletResponse response,Login command) throws Exception {

    System.out.println("Authenticating user : ");
    ModelAndView mv = new ModelAndView("welcome","command",command);
    mv.addObject("command",command);

    BindException errors = super.bindObject(request, command, new LoginValidator());

    if(errors.hasErrors()) {

    mv.addAllObjects(errors.getModel());

    mv.setViewName("login");
    return mv;

    }


    return mv;
    }

    Here is the bind method in multiaction controller
    protected void bind(HttpServletRequest request, Object command) throws Exception {
    ServletRequestDataBinder binder = createBinder(request, command);
    binder.bind(request);

    }

    and in the loginValidator --

    public void validate(Object target, Errors errors) {

    Login login = (Login) target;


    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userId", "error.not-specified", "field can not be empty");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "error.not-specified", "field can not be empty");
    }


    it works fine if u have defined the properties file to show the errors in jsp using <form:errors path> and command object is Login with userId and password properties
    Last edited by luv_spring; Jun 21st, 2011 at 07:15 AM.

  2. #72

    Default

    problem with based controller and some source code

  3. #73
    Join Date
    Oct 2012
    Location
    India
    Posts
    1

    Default

    thanks all of you. you solved my problem about Multi Action Controller. you all have a great job.

    Thanks
    click here for car insurance India , where to buy car insurance online .

    Buy health , Car & travel insurance online.

Posting Permissions

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