This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Spring and the fly likes BindingResult nor plain target object for bean name 'usersuccess' available as request attribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "BindingResult nor plain target object for bean name Watch "BindingResult nor plain target object for bean name New topic
Author

BindingResult nor plain target object for bean name 'usersuccess' available as request attribute"

shyampriya soni
Greenhorn

Joined: May 16, 2012
Posts: 1
hello....
I am trying to develop web application using spring mvc framework which contain 2 form.
1. user form 2. usersuccess form
i am using 2 controllers for these two forms. i am able to disblay my first form but when i click on submit button on user form i got following error
"java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'usersuccess' available as request attribute"

please help

my code:

User.java

ackage com.vaannila.domain;

public class User {

private String name;
private String password;


public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}


UserSuccess.java


package com.vaannila.domain;

public class UserSuccess {

protected String amtinfo;
protected String amtwithdraw;


public String getAmtInfo() {
return amtinfo;
}
public void setAmtInfo(String amtinfo) {
this.amtinfo = amtinfo;
}
public String getAmtWithdraw() {
return amtwithdraw;
}
public void setAmtWithdraw(String amtwithdraw) {
this.amtwithdraw = amtwithdraw;
}
}

UserController.java
package com.vaannila.web;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
import com.vaannila.domain.User;


@SuppressWarnings("deprecation")
public class UserController extends SimpleFormController {


User user = new User();
public UserController() {
setCommandClass(User.class);
setCommandName("user");
}


@Override
protected ModelAndView onSubmit(Object command) throws Exception {
User user = (User) command;
return new ModelAndView("userSuccess","user",user);
}

}

UserSuccesController.java

package com.vaannila.web;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;


import com.vaannila.domain.UserSuccess;


@SuppressWarnings("deprecation")
public class UserSuccessController extends SimpleFormController {



UserSuccess usersuccess = new UserSuccess();
public UserSuccessController(){
setCommandClass(UserSuccess.class);
setCommandName("usersuccess");
}

@Override
public ModelAndView onSubmit(Object commandName) throws Exception {
UserSuccess usersuccess = (UserSuccess) commandName;
return new ModelAndView("logout","usersuccess",usersuccess);
}

}

dispactcher-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />

<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource"
p:basename="/WEB-INF/messages" />

<bean id="userValidator"
class="com.vaannila.validator.UserValidator" />

<bean name="/userRegistration.htm"
class = "com.vaannila.web.UserController"
p:formView = "userForm" p:successView="userSuccess" p:validator-ref="userValidator" />

<bean name="/usersuccesss.htm" class="com.vaannila.web.UserSuccessController">
<property name="commandName" value="usersuccess"/>
<property name="commandClass" value="com.vaannila.domain.UserSuccess"/>
<property name="formView" value="userSuccess"/>
<property name="successView" value="logout"/>
</bean>

</beans>















Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Please use the CODE tags when posting code and configuration. I can't read the code without the indentations.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Also, if you are just learning Spring and Spring MVC, I recommend using material that is up to date.

public class UserController extends SimpleFormController

extending or implementing any Spring Controller class or Interface is not recommended for at least the past 5 years, and are actually now deprecated.

It is much easier and better to use Annotations and current Spring MVC.

Mark
 
 
subject: BindingResult nor plain target object for bean name 'usersuccess' available as request attribute"
 
Similar Threads
que in spring mvc - simpleformcontroller
Getting the below error when doing formvalidation in spring
Javascript new window is not opening from a jsp page
Not Getting Values using EL in Spring..
Problem in using javascript in spring web mvc system: