Announcement Announcement Module
Collapse
No announcement yet.
status.errorMessage is not showing message Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • status.errorMessage is not showing message

    I have just started to learn Spring MVC. I started with making a small application. I use SimpleFormController and Varlidator in that. A logonForm.jsp page has been created. It is loading successfully, but when i m inserting no values in the username and password, i expect the error message from status.errorMessage from the frame work. I am attaching code with this also. Can anyone help me to sort it out.

    UserBean

    package com.deepa.beans;

    public class UserBean {

    private String userName;
    private String password;

    public String getPassword() {
    return password;
    }

    public void setPassword(String password) {
    this.password = password;
    }

    public String getUserName() {
    return userName;
    }

    public void setUserName(String userName) {
    this.userName = userName;
    }
    }
    ----------------------------------------------------

    logonFormValidator

    package com.deepa.validators;

    import com.deepa.beans.UserBean;
    import org.springframework.validation.Errors;
    import org.springframework.validation.Validator;

    public class LogonFormValidator implements Validator{

    public boolean supports(Class clazz) {
    return clazz.equals(UserBean.class);
    }

    public void validate(Object obj, Errors errors) {
    UserBean user = (UserBean)obj;
    if(user == null){
    errors.rejectValue("username", "error.login.not-specified", "value required.");
    } else {
    if(user.getUserName() == null || user.getUserName().trim().length() <= 0){
    System.out.println("User Name Null Value");
    errors.rejectValue("userName", "error.login.invalid-user", null, "Username is Required");
    } else {
    if(user.getPassword() == null || user.getPassword().trim().length() <= 0){
    System.out.println("Password Null Value");
    errors.rejectValue("password", "error.login.invalid-pass", null, "Password is Required");
    }
    }
    }
    }
    }

    ---------------------------------------------------------------------

    logon.jsp

    <html>
    <head>
    <title>Spring Validation Example</title>
    </head>
    <body>
    <center>
    <h1>Spring Validation Example</h1>
    <br>
    <spring:hasBindErrors name="userBean">
    <c:if test="${not empty status.errorMessage}">
    <font color="red"><c:out value="${status.errorMessage}"/></font>
    </c:if>
    </spring:hasBindErrors><br>
    <form method="post" action="logonForm.htm">
    <table width="25%" border="1">
    <tr>
    <td align="center" bgcolor="lightblue">Log on</td>
    </tr>
    <tr>
    <td>
    <table border="0" width="100%">
    <tr>
    <td width="33%" align="right">Username:</td>
    <td width="66%" align="left">
    <spring:bind path="userBean.userName">
    <input type="text" name="userName" value="${status.value}"/>
    </spring:bind>
    </td>
    </tr>
    <tr>
    <td width="33%" align="right">Password:</td>
    <td width="66%" align="left">
    <spring:bind path="userBean.password">
    <input type="password" name="password" value=""/>
    </spring:bind>
    </td>
    </tr>
    <tr>
    <td colspan="2" align="center">
    <input type="submit" value="Submit"/>
    </td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </form>
    </center>
    </body>
    </html>

  • #2
    Can you please post code inside [code]-tags!
    Where is your controller code?

    Comment


    • #3
      status.errorMessage is not showing message

      here is my controller class


      package com.deepa.controllers;

      import javax.servlet.ServletException;
      import javax.servlet.http.HttpServletRequest;

      import org.springframework.web.servlet.ModelAndView;
      import org.springframework.web.servlet.mvc.SimpleFormCont roller;

      public class LogonController extends SimpleFormController{

      public Object formBackingObject(HttpServletRequest request) throws ServletException{
      UserBean backingObject = new UserBean();
      System.out.println("formbackingobject");
      return backingObject;
      }

      public ModelAndView onSubmit(Object command) throws ServletException{
      UserBean user = (UserBean) command;
      System.out.println("username : " + user.getUserName());
      System.out.println("password : " + user.getPassword());
      return new ModelAndView("success");
      }
      }

      Comment


      • #4
        status.errorMessage is not showing message

        I am unable to post the list of taglib i used there. But i used the the tld of

        1) for core jslt i used : /jsp/jstl/core
        2) form format i used : /jstl/fmt
        3) for spring i used : /tags

        Comment

        Working...
        X