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.

Any Java questions or problems? please post at this JavaNullPointer.com forum, see you there ~
[ Read More ] You can find more similar articles at Spring MVC Tutorials