permaculture playing cards*
The moose likes Spring and the fly likes How to do server side validation in Spring with MultiActionController ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "How to do server side validation in Spring with MultiActionController ?" Watch "How to do server side validation in Spring with MultiActionController ?" New topic
Author

How to do server side validation in Spring with MultiActionController ?

purvang joshi
Greenhorn

Joined: May 11, 2011
Posts: 1
*Hello Friends.*
*Can anybody suggest me how to do serverside validation in spring while extemding controller with multiActionController*
*I am trying to do this with below code but its not working*

*public class LoginController extends MultiActionController {*
* *
* public LoginController()*
* {*
* setMethodNameResolver(new InternalPathMethodNameResolver());*
* setValidators(new Validator[] { new Validator() {*
* public boolean supports(Class clazz) {*
* return clazz.isAssignableFrom(LoginDetailDTO.class);*
* }*

* public void validate(Object command, Errors errors) {*
* ValidationUtils.rejectIfEmpty(errors, "userId", "", "Age is required");*
* ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "",*
* "Name is required");*
* }*

* *
* } });*

* }*

* HttpSession session;*
* *
* public ModelAndView login(HttpServletRequest request,*
* HttpServletResponse response)*
* throws Exception*
* {*
* *
* *
* return new ModelAndView("home");*
* }*
* *
* public ModelAndView validateUser(HttpServletRequest request,*
* HttpServletResponse response,LoginDetailDTO command)*
* throws Exception*
* {*
* *
* *
* String fileName="";*
* String message="";*
* LoginDetailDTO d=(LoginDetailDTO)command;*
* *
* LoginDetailDTO loginDetailDTO=new LoginDetailDTO();*
* loginDetailDTO.setUserId(request.getParameter("userId"));*
* loginDetailDTO.setPassword(request.getParameter("password"));*
* *
* LoginDetailDTO user = getLoginServie().authenticateUser(loginDetailDTO);*
* *
* session=request.getSession();*
* ModelAndView mv=new ModelAndView();*
* mv.addObject("bindObj", request);*
* if(null != user)*
* {*
* session.setAttribute("user",user);*
* if(null != user.getFirstTimeLogin() && user.getFirstTimeLogin().equalsIgnoreCase("Y")){*
* *
* fileName = "password";*
* }else{*
* fileName="main";*
* }*
* }else{*
* //user name or password incorrect*
* fileName="home";*
* message="Incorrect User ID or Password";*
* }*
* *
* *
* return new ModelAndView(fileName,"message",message);*
* *
* }*
* *
* *
* *
* *
* *
* *
*}*


*Please help me on this*
 
Consider Paul's rocket mass heater.
 
subject: How to do server side validation in Spring with MultiActionController ?