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

G

ganesh

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top