Announcement Announcement Module
Collapse
No announcement yet.
problem in validation Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • problem in validation

    what is the recommended way of error handling(validations) when using the MultiActionController

    problem
    1]when my login page contains some empty field then it shouild show some
    error message

    but when flow coming out of the validate mathod of validator

    Exception is thrown

    as follows


    INFO: Using JSP 2.0 ExpressionEvaluator
    class com.dss.ems.models.UserModel
    i am in support method
    class com.dss.ems.models.UserModel
    i am in support method
    i am in i am in validate method
    coming out from validator

    20-Dec-2005 09:57:13 org.springframework.web.servlet.FrameworkServlet processRequest
    SEVERE: Could not complete request
    org.springframework.web.bind.ServletRequestBinding Exception: Errors binding onto object 'command'
    at org.springframework.web.bind.ServletRequestDataBin der.closeNoCatch(ServletRequestDataBinder.java:14
    5)
    at org.springframework.web.servlet.mvc.multiaction.Mu ltiActionController.bind(MultiActionController.ja
    va:448)
    at org.springframework.web.servlet.mvc.multiaction.Mu ltiActionController.invokeNamedMethod(MultiAction
    Controller.java:400)
    at org.springframework.web.servlet.mvc.multiaction.Mu ltiActionController.handleRequestInternal(MultiAc
    tionController.java:358)
    at org.springframework.web.servlet.mvc.AbstractContro ller.handleRequest(AbstractController.java:139)
    at org.springframework.web.servlet.mvc.SimpleControll erHandlerAdapter.handle(SimpleControllerHandlerAd



    root cause is
    org.springframework.validation.BindException: BindException: 2 errors; Field error in object 'command' on field 'userName': rejected value []; codes [UserName kept blank.command.userName,UserName kept blank.userName,UserName kept blank.java.lang.String,UserName kept blank]; arguments []; default message [null]; Field error in object 'command' on field 'userPassword': rejected value []; codes [Password kept blank.command.userPassword,Password kept blank.userPassword,Password kept blank.java.lang.String,Password kept blank]; arguments []; default message [null]
    org.springframework.validation.DataBinder.createEr rors(DataBinder.java:126)
    org.springframework.validation.DataBinder.<init>(D ataBinder.java:112)
    org.springframework.web.bind.WebDataBinder.<init>( WebDataBinder.java:67)



    my validation class's methods are

    public boolean supports(Class clazz) {
    System.out.println(clazz);
    System.out.println(" i am in support method ");
    return clazz.equals(UserModel.class);
    }

    public void validate(Object obj,Errors errors){
    System.out.println(" i am in i am in validate method ");
    UserModel um=(UserModel)obj;

    ValidationUtils.rejectIfEmpty(errors,
    "userName",Constants.ERROR_MESSAGE_FOR_BLANK_USERN AME);

    ValidationUtils.rejectIfEmpty(errors,
    "userPassword",Constants.ERROR_MESSAGE_FOR_BLANK_P ASSWORD);

    System.out.println("coming out from validator");
    }


    my jsp page's part

    <form method="POST"
    action="auth.htm">
    <table width="400"
    border="0"
    cellspacing="5"
    cellpadding="0">

    <tr>
    <spring:hasBindErrors name="usermodel">
    <b>invalid UserName/Password </b>
    </spring:hasBindErrors >

    </tr>
    <tr>
    <td align="right" valign="middle">
    <b>Login:</b>
    </td>
    <td align="left" valign="middle">
    <spring:bind path="usermodel.userName">
    <input type="text"
    name="<c:out value="${status.expression}"/>" value="<c:out value="${status.value}"/>">
    </spring:bind>
    </td>
    </tr>
    <tr>
    <td align="right" valign="middle">
    <b>Password:</b>
    </td>
    <td align="left" valign="middle">
    <spring:bind path="usermodel.userPassword">

    <input type="password"
    name="<c:out value="${status.expression}"/>" value="<c:out value="${status.value}"/>">

    </spring:bind>
    </td>
    </tr>
    <td colspan="2" align="center">
    <INPUT type="image"
    src="./images/Login.gif"
    Onclick="javaScript:submitForm('Login')">
    </td>
    </table>
    </form>


    my controller code is

    public class LoginController extends MultiActionController implements Controllable {

    private Delegatable delegatableProxy=null;

    public LoginController() {
    System.out.println(" In LoginController ");
    }

    public void setDelegatableProxy(Delegatable delegatableProxy ) {
    this.delegatableProxy=delegatableProxy;
    }

    public Delegatable getDelegatableProxy() {
    return this.delegatableProxy;
    }




    /*this method is used to dispatch login page to user who wants to acess the system
    *
    **/
    public ModelAndView showLoginPage(HttpServletRequest request,
    HttpServletResponse response,
    Object obj) throws ServletException {
    System.out.println("i am giving login page");
    ModelAndView mav=new ModelAndView("login");
    mav.addObject("usermodel",new UserModel());
    return mav;
    }



    public ModelAndView authenticateUser( HttpServletRequest request,
    HttpServletResponse response,
    UserModel command){
    System.out.println(" iam in authentication "+command.getClass());
    UserModel lc = command;
    UserModel um =getDelegatableProxy().authenticateUser( lc.getUserName(),
    lc.getUserPassword());


    if(um==null) {
    System.out.println(" user model is null");
    ModelAndView mav=new ModelAndView("login");
    mav.addObject("usermodel",new UserModel());

    //mav.addObject("ErrorMessage",Constants.ERROR_MESSA GE_FOR_INVALID_USERNAME_PASSWORD);
    return mav;
    }else {
    System.out.println("you are valid user");
    return new ModelAndView("Expense");

    }
    }


    }
    Last edited by ganesh pol; Dec 20th, 2005, 02:11 AM.
Working...
X