• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

how to tell MultiActionController Command Object is Of type com.dss.ems.model.User

 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi friends
normally in spring's simple form controller we are registering one command object for one controller
like following code

<beanid="loginController"
class ="com.dss.ems.controllers.LoginController">
<property name="sessionForm"><value>true</value></property>
<property name="commandName"><value>usermodel</value></property>
<property name="commandClass"><value>com.dss.ems.models.UserModel</value></property>



but in multiaction controller how should we proceed to register one command object for one method


i will give u one example


my Controller code is


public class LoginController extends MultiActionController{
private Map userMap=null;

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

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;
}


// problem part
public ModelAndView authenticateUser(HttpServletRequest request,
HttpServletResponse response,
Object command){
System.out.println(" iam in authentication"+command.getClass());
UserModel loginCommand = (UserModel) command;
// in user map we set the username as key
if( loginCommand.getUserName()!=null &&
loginCommand.getPassword()!=null &&
(loginCommand.getPassword()).equals(
(this.getUserMap()).get(loginCommand.getUserName() ))
) {
System.out.println("you are valid user");
return new ModelAndView("Expense");
}
else {
System.out.println("you are NOT valid user");
//throw new UserNotFoundException();
return new ModelAndView("login");
}
}

public void setUserMap(Map userMap) {
this.userMap =userMap;
}

public Map getUserMap() {
return this.userMap;
}
}

MY JSP PAGE IS

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="spring" uri="/spring" %>


<html>
<head>
<title>
Login to Expense Management System
</title>
</head>
<body>

<table width="742" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2" style="color:#FFFFFF;background-color:#666699;height:100px;"><span style="font-size:24pt;">
EXPENSE MANAGEMENT SYSTEM
</td>
</tr>
<tr>
<td width="742" valign="top">
<table width="742" border="0" cellspacing="0" cellpadding="0">
<tr>
<td
style="font-size:14pt;color:#FFFFFF;background-color:#9999CC;" align="right">
Login
</td>
</tr>
<tr>
<td valign="top" style="font-size:10pt;" align="center">
<form method="POST"
action="auth.htm">
<table width="400"
border="0"
cellspacing="5"
cellpadding="0">
<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>
</tr>
<tr>
<td align="right" valign="middle">
<b>Password:</b>
</td>
<td align="left" valign="middle">
<spring:bind path="usermodel.password">

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

</spring:bind>
</td>
</tr>
<td colspan="2" align="center">
<input type="submit">
</td>
</table>
</form>
<br>
<br>
<a href=""><B>FORGOT PASSWORD</B></a>.
<br><br> 
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>

AND XML FILE IS

<beans>

<bean id="simpleUrlMapping"
class = "org.springframework.web.servlet.handler.SimpleUrl HandlerMapping">
<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="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>

</bean>
<!-- =========================Method name resolver ========================= -->

<bean id="LoginControllerMethodNameResolver"
class="org.springframework.web.servlet.mvc.multiac tion.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.LoginFormValidat or"/>
-->




<bean id="viewResolver"
class = "org.springframework.web.servlet.view.InternalReso urceViewResolver">
<property name="viewClass">
<value>org.springframework.web.servlet.view.JstlVi ew</value>
</property>
<property name ="prefix">
<value>/jsp/</value>
</property>
<property name ="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>

AND ERROR ON SERVER SIDE IS


INFO: Using JSP 2.0 ExpressionEvaluator
iam in authentication class java.lang.Object
14-Dec-2005 14:27:16 org.springframework.web.servlet.FrameworkServlet processRequest
SEVERE: Could not complete request
java.lang.ClassCastException
at com.dss.ems.controllers.LoginController.authentica teUser(LoginController.java:
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.j
at java.lang.reflect.Method.invoke(Method.java:324)
at org.springframework.web.servlet.mvc.multiaction.Mu ltiActionController.invokeNa
Controller.java:403)
at org.springframework.web.servlet.mvc.multiaction.Mu ltiActionController.handleRe
tionController.java:358)
at org.springframework.web.servlet.mvc.AbstractContro ller.handleRequest(AbstractC
at org.springframework.web.servlet.mvc.SimpleControll erHandlerAdapter.handle(Simp
apter.java:44)
at org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet


problem is that how should i tell my MultiActionController Command Object is Of type com.dss.ems.models.Usermodel and not java.lang.Object



please help me friends

[ December 12, 2005: Message edited by: ganesh pol ]
[ December 14, 2005: Message edited by: ganesh pol ]
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I did it in this way:


I did not set anything in the xml file, but the form fields mataches to the CalVO.
Hope this helps you.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the old method definition
void ModelAndView xxxxx(HttpServletRequest req , HttpServletResponse res , Object obj ){}

change the Object class to the Class that you want to convert
ex
void ModelAndView xxxxx(HttpServletRequest req , HttpServletResponse res , User obj ){}

So that while binding the Class of the User command object will be taken and the values from the request parameters will be bound
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rajarshi Ghosh and Arunkumar spk,
Could you please elaborate on your answers? Thanks!

I'm new to Spring as well (and first time poster) and have the exact same error. The bind method mentioned above - where did you add it and how did you use it?

Thanks for any info!
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Arunkumar spk" and "Reshma RB", please check your private messages for an important administrative matter.
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Team,

I have the same problem with the bind. How do I bind the command object in controller.

Did anybody solve this problem. If yes, can you please post the code for:
1. accessing command object in method of MultiactionController
2. JSP code ( do I need any additional tags to bing object)?
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I also have the same question.
Flow from JSP-->Controller-->Jsp in multiactionController is vague to me.

My MultiActionController:-
public ModelAndView changePassword(HttpServletRequest request, HttpServletResponse response, Users users) {
/*My Code here.
*/
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("changepassword");
modelAndView.addObject("users", users);
return modelAndView;

}


my Jsp:
<form action="changepassword.htm">
<spring:bind path="users.password">
<input type="password" name="password">
</spring:bind>
</form>

I get this exception & nothing is displayed on the browser window:-
javax.servlet.jsp.JspTagException: Neither BindingResult nor plain target object for bean name 'users' available as request attribute

 
We don't have time to be charming! Quick, read this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic