Spring MVC – Neither BindingResult nor plain target object for bean name ‘xxx’ available as request attribute.

Problem

Recently, just converted the Spring MVC xml-based form controller to annotation-based form controller, and hits the following error message.

SEVERE: Neither BindingResult nor plain target object for bean name ‘customerForm’ available as request attribute
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name ‘customerForm’ available as request attribute


Above error message is clearly indicated that the “customerForm” bean is not exists, and i 100% sure the view resolver is configured properly and the “CustomerForm.jsp” view page is existed.

Form Controller


@Controller
@RequestMapping("/customer.htm")
public class CustomerController{

       @RequestMapping(method = RequestMethod.GET)
	public String initForm(ModelMap model){
		//return form view
		return "CustomerForm";
	}

View Resolver


         ...
	<bean id="viewResolver"
	      class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
              <property name="prefix">
                  <value>/WEB-INF/pages/</value>
              </property>
              <property name="suffix">
                 <value>.jsp</value>
             </property>
        </bean>

Solution

The root caused is the incorrect view name in JSP page, see below.


<form:form method="POST" commandName="customerForm">

The “customerForm” is not exists in the controller mapping anymore, see annotation mapping @RequestMapping(“/customer.htm”), it should change to “customer”.


<form:form method="POST" commandName="customer">

Similar Cases

I’ve seen quite many similar cases happened in validator or SimpleFormController class as well. To solve it, just make sure the mapping name is matched or existed.

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
18 Comment threads
7 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
22 Comment authors
aroradeepali44arun singhAvril Sioson-MirandaAjeet DeginalNarendra Recent comment authors
newest oldest most voted
Lenny
Guest
Lenny

I also had the same problem as “Neither BindingResult nor plain target object for bean name…..”, but my problem was that in my jsp I was using <form…. instead of <form:form….. since I was using the form taglib, I needed to use <form:form. This solved the problem for me.

Mikkel
Guest
Mikkel

Thank you mkyoung! 🙂 I Just had a similar problem and this helped me out.

AVA
Guest
AVA

Add Model Attribute as follows to resolve the issue:

@ModelAttribute(“customer”)
public Customer getCustomerObject() {
return new Customer();
}

read posts :
(1) http://stackoverflow.com/questions/8781558/neither-bindingresult-nor-plain-target-object-for-bean-name-available-as-request
(2) http://stackoverflow.com/questions/1069958/neither-bindingresult-nor-plain-target-object-for-bean-name-available-as-request

Avril Sioson-Miranda
Guest
Avril Sioson-Miranda

Hi,

Thanks for pointing this out 🙂

Nagendra Gupta
Guest
Nagendra Gupta

Did the same as you tole bust still problem coming??

jaime
Guest
jaime

Thank you, I was confusing the ‘commandName’ attribute

alle
Guest
alle

“Neither BindingResult nor plain target object for bean name ‘xxx’ available as request attribute
one of the root causes for this exception is.
we must set the object instance in request of jsp page.
eg:

Shabs
Guest
Shabs

Thanks Mkyong,

Many of your posting have been of great help to me. Really appreciate and admire your good work. Thanks again.

Shabs

Christian
Guest
Christian

This could also happen if you are passing a class object with a null value into the ModelAndView. In which case you must at least instantiate a new instance of the class.

Carol
Guest
Carol

Thank you for any other great article. The place else may just anybody get that type of information in such a perfect manner of writing?

I’ve a presentation subsequent week, and I’m at the look for such information.

ybaburao
Guest
ybaburao

I am a new to Spring 2.5 MVC, and I need some help. I must be missing something, but I can’t figure out what. It is giving java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name ‘user’ available as request attribute , when i clicked on MyLogin url. Here Iam trying to using UrlFilenameViewController and SimpleFormController. index.jsp: ———- UrlFileNameViewController Example My Login My Office Address Iam using UrlFilenameViewController to display this page dispatcher-servelt.xml: ————————— /WEB-INF/jsp/ .jsp true user com.model.User when i run index.jsp , it will display MyLogin and MyOffice Login when i click on MyLogin Link in getting… Read more »

puneet kumar agarwal
Guest
puneet kumar agarwal

the post has been very informative and helped to find the issue. save my day. thanks and keep posting 🙂

Prabhat Singh
Guest
Prabhat Singh

Thanks helped me

Mounir Igorman
Guest
Mounir Igorman

i have the same probleme and i can”t resolve it yet !!
this is my controller
@RequestMapping(value=”/addProduct”, method = RequestMethod.POST)
public String addProduct(Model model,@ModelAttribute(“produit”) Produit produit,BindingResult result){
produitValidator.validate(produit,result);
if (!result.hasErrors()) {
services.addProduit(produit);
model.addAttribute(“produit”,new Produit());
model.addAttribute(“listeProduit”, services.getAllProduits());
return “produits”;
}else return “error”;
}

this is my jsp

nom:

Shekar Chandra
Guest
Shekar Chandra

java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name ‘loginform’ available as request attribute

Could someone please help me out here

Narendra
Guest
Narendra

Neither BindingResult nor plain target object for bean name ‘xxx’ available as request attribute

I am using SimpleFormController not RequestMapping Annotaion.could u plz help me in resolving the issue.
Thanks

Ajeet Deginal
Guest
Ajeet Deginal

My controller: @RequestMapping(method=RequestMethod.POST, value=”/searchCompanyDetails”) public String searchCompanyDetails(ModelMap model, @ModelAttribute(“company”) CompanyDetails company, HttpServletRequest request){ model.put(“companyName”, company.getCompanyName()); model.put(“contact”, new ContactInformationDTO()); List categoryList = services.getCategryList(); model.put(“categorylist”, categoryList); model.put(“comcat”, new CategoryCompanyDTO()); return “addCategory2”; } My JSP: <%– –%> Error: SEVERE: Servlet.service() for servlet [ConceptEdgeDetails] in context with path [/ConceptEdge] threw exception [An exception occurred processing JSP page /WEB-INF/views/addCategory2.jsp at line 55 java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name ‘contact’ available as request attribute Please help me where I am doing wrong?

arun singh
Guest
arun singh

this exception occurs when the spring container does not find “customerForm” named key in Model-map in the Session of Controller. The form data are considered as “value” and “customerForm” is “key”.
To resolve it, you should keep a “Customer” object ready so that given “commandName”‘s value can be saved into the object first.
Solution= model.addAttribute(“customerForm”, new Customer()); //when the request comes for the first time, you should attach a Customer object to the Model, means you are making target object available for the commandName.