
Originally Posted by
saravanansivaji
I think the code is already available in this thread, given by one of our friend jerry, thanks to him. Anyhow I will repaste the code here
The following is my multi action controller,
public class MyController extends MultiActionController
{
BindingResult errors; //Declaring errors as instance variable to catch error
/** My overidden bind() method */
protected void bind(HttpServletRequest request, Object command) throws Exception
{
ServletRequestDataBinder binder = createBinder(request, command);
binder.bind(request);
errors = binder.getBindingResult();
}
/** My validator */
public void MyValidator(Object command)
{
/** Invoking validator **/
Validator[] validators = getValidators();
if (validators != null)
{
for (int index = 0; index < validators.length; index++)
{
Validator validator = validators[index];
if (validator instanceof CustomerInfoValidator)
{
if (((CustomerInfoValidator)validator).supports(comma nd.getClass())) ValidationUtils.invokeValidator(validators[index], command, errors);
}
else if (validator.supports(command.getClass()))
ValidationUtils.invokeValidator(validators[index], command, errors);
}
}
}
/** this is my method handler */
public ModelAndView newcontactHandler(HttpServletRequest request, HttpServletResponse response)
{
if(errors.hasErrors())
{
return new ModelAndView("addcontact",errors.getModel());
}
return new ModelAndView("add-success");
}
}
}
}
I hope this help, If u can't understand let me know...