how to handle error (in validation) in spring's MultiActionController

Discussion in 'Java' started by ganesh, Dec 20, 2005.

  1. ganesh

    ganesh Guest

    i don't know how to display error messages in jsp with the help of
    MultiActionController

    consider following
    i have login.jsp if my username or password field is empty then it
    should (jsp page) display error message

    ERROR MESSAGE ON SERVER IS
    when i kept either of the field empty i have got following Exception
    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)


    VALIDATION METHOD IS
    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");
    }


    part of jsp page is

    <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="<cut value="${status.expression}"/>" value="<cut
    value="${status.value}"/>">
    </spring:bind>
    </td>


    my LoginController 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");

    }
    }


    }


    XML DEFINATION IS

    <beans>
    <bean id="simpleUrlMapping"
    class =
    "org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    <property name ="mappings">
    <props>
    <prop key ="login.htm">loginController</prop>
    <prop key ="auth.htm">loginController</prop>
    </props>

    </property>
    </bean>




    <!-- ========================= CONTROLLER DEFINITIONS
    ========================= -->
    <bean id="loginController"
    class ="com.dss.ems.controllers.LoginController">
    <property name="methodNameResolver"
    ref="LoginControllerMethodNameResolver"/>
    <property name="delegatableProxy"
    ref="delegatorProxy"/>
    <!--
    <property name="userMap">
    <map>
    <entry>
    <key><value>gp</value></key>
    <value>gp</value>
    </entry>
    <entry>
    <key><value>jk</value></key>
    <value>jk</value>
    </entry>
    <entry>
    <key><value>sb</value></key>
    <value>sb</value>
    </entry>
    <entry>
    <key><value>dd</value></key>
    <value>dd</value>
    </entry>
    </map>
    </property>
    -->
    <property name="validators">
    <list>
    <bean class="com.dss.ems.formvalidators.LoginFormValidator"/>
    </list>
    </property>

    </bean>
    <!-- =========================Method name resolver
    ========================= -->
    <bean id="LoginControllerMethodNameResolver"
    class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver">

    <property name="mappings">
    <props>
    <prop key="/login.htm">showLoginPage</prop>
    <prop key="/auth.htm">authenticateUser</prop>
    </props>

    </property>

    </bean>

    <!--
    <bean id="loginFormValidator"
    class="com.dss.ems.formvalidators.LoginFormValidator"/>
    -->


    please help me
    ganesh, Dec 20, 2005
    #1
    1. Advertising

  2. ganesh

    anil_impact

    Joined:
    Nov 27, 2009
    Messages:
    1
    www.scribd.com/doc/.../Multi-Action-Controller-With-Validation

    Hi Gopal,
    You can go through the example which has given in the above scribd site.Which is so easy to do and i checked it .Its working fine.Your problem will solve very easily.
    Last edited: Nov 27, 2009
    anil_impact, Nov 27, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dietrich
    Replies:
    1
    Views:
    636
    Joe Smith
    Jul 22, 2004
  2. ganesh
    Replies:
    0
    Views:
    1,004
    ganesh
    Dec 20, 2005
  3. javadude
    Replies:
    1
    Views:
    902
    Raymond DeCampo
    Jan 10, 2006
  4. rmn190
    Replies:
    2
    Views:
    2,352
    Arne Vajhøj
    Jan 10, 2008
  5. Goldfish
    Replies:
    1
    Views:
    691
    Goldfish
    Nov 6, 2008
Loading...

Share This Page