Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Standard view
Full view
of .
Look up keyword
Like this
0 of .
Results for:
No results containing your search query
P. 1
Multi Action Controller With Validation

Multi Action Controller With Validation



|Views: 11,164|Likes:
Published by Santosh Kothapalli
This tutorial explains in detail as how to create a multiaction controller along with validations in spring
This tutorial explains in detail as how to create a multiaction controller along with validations in spring

More info:

Published by: Santosh Kothapalli on Sep 24, 2009
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less





 MultiActionController with ValidationDescription:
Spring supports a multiaction controller where themultiple actions on a form can be grouped to a single controller. Themultiaction controller supports the mapping of requests to methodnames which are similar to what Dispatch Action of struts do and itdoes a bit more than that in terms of delegation of the requests.
Problem Description:
A Simple Login page with two buttons, which takeuser name and password as the inputs. The page has two buttons,authenticate and login as shown below and performs validation onclick of the buttons.
Implementation:Step 1
: Configuring the spring main servlet (DispatcherServlet) inweb.xmlIn the web.xml we have named the servlet as spring; hence the springcontext file is required to be named as
Step 2:
Configuring the LoginController(MultiActionController) andthe LoginValidator in
The LoginController has the two setter methods
setMethodNameResolver – this identifies the method that ismapped to a particular request, the MethodNameResolver takestwo values
– The hidden variable that we declare in thelogin.jsp page, whose value needs to be set as the nameof the method name in the controller.
– The method name of the controllerthat is executed when the page is loaded.
setValidators – this identifies the set of vallidators that thecontroller can execute in our example LoginValidator
Step3 :
Creating the login page login.jspWe have two buttons Authenticate and Register, which when clickedinvoke the javascript method setAction() which will set the value ofthe hidden variable by name
which is configured in the
as the
which identifies the name of themethod of the controller class to be invoked.<%@taglibprefix="form" uri="http://www.springframework.org/tags/form"%> <%@taglibprefix="spring"uri="http://www.springframework.org/tags" %><%@taglibprefix="c"uri="http://java.sun.com/jstl/core_rt"%> <html><body><scripttype="text/javascript"> functionsetAction(action1){ document.forms[0].methodToCall.value = action1;document.forms[0].submit();}
</script> <style> .error{ color:red;}  </style>  <c:iftest="${
not empty
errors}"> <divclass="error">  <c:forEachvar="error"items="${errors}">  <c:outvalue="${error}"escapeXml="false"/><br/>  </c:forEach>  </div> </c:if><form:formmethod="post"commandName="command">  <tablewidth="95%"bgcolor="f8f8ff"border="0"cellspacing="0" cellpadding="5">  <tr>  <tdalign="right"width="20%">UserId</td>  <tdwidth="20%">  <spring:bindpath="command.userid">  <form:inputpath="userid"/>  </spring:bind>  </td>  <tdwidth="60%">  <form:errorspath="userid"cssClass="error"/>  </td>  </tr>  <tr>  <tdalign="right"width="20%">Password</td>  <tdwidth="20%">  <spring:bindpath="command.password">  <form:inputpath="password"/>  </spring:bind>  </td>  <tdwidth="60%">  <form:errorspath="password"cssClass="error"/>  </td>  </tr>  <tr>
  <td align="right"width="20%"   <inputtype="button"align="middle" value="Authenticate" onclick="javascript:setAction('authenticateUser');"   </td ><td width="20%"   <inputtype="button"align="middle" value="Register" onclick="javascript:setAction('registerUser');"   </td 
 </tr> </table> <br>
  <inputtype="hidden"name="methodToCall" value=""/> 

Activity (104)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
Rajesh Kumar added this note
this is not working
Nguyen Ct liked this
Vineet Pareek liked this
Vineet Pareek liked this
Hai Thinh liked this
Phillip Dunham added this note
Controllers are singletons. Seems like a really bad idea to store Binding errors specific to a request as an attribute of the controller.
vivek2166 liked this
kvaradh1 liked this

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->