PDA

View Full Version : Spring MVC and Tiles issue:Neither BindingResult nor plain target object for bean nam



nitin.vashi
Dec 6th, 2010, 07:03 PM
Hi All,

I am using Spring MVC 3.0 and tiles 2.1.

My flow is pretty simple, but I am getting the below exception while trying to render to my jsp page:

java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'newPatientRegistration' available as request attribute

Below are the important parts of my application.

1. springapp-servlet.xml:

<bean name="/newPatientForm.htm" class="springapp.web.NewPatientFormController" />


<bean name="/newPatientRegistration.htm" class="springapp.web.NewPatientRegistrationController">
<property name="sessionForm" value="true"/>
<property name="commandName" value="newPatientRegistration"/>
<property name="commandClass" value="springapp.service.NewPatientRegistration"/>
<!--property name="validator"
<bean class="springapp.service.PatientDataValidator"/>
</property-->
<property name="formView" value="newPatientFormTile"/>
<property name="successView" value="newPatientForm.htm"/>
<property name="newPatientManager" ref="newPatientManager"/>
</bean>

2. Controller class:
public class NewPatientFormController implements Controller{

protected final Log logger = LogFactory.getLog(getClass());

public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {

logger.info("Returning newPatientFormTile.");
return new ModelAndView("newPatientFormTile");
}

3. Tiles definition:
<definition name="newPatientFormTile" extends="standardLayout">
<put-attribute name="body" value="/WEB-INF/jsp/newPatientRegistration.jsp" />
<put-attribute name="leftNevigator" value="/WEB-INF/jsp/leftNegivator.jsp" />
</definition>

4. newPatientRegistration.jsp

<%@ include file="/WEB-INF/jsp/include.jsp" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

<html>
<head>
<title><fmt:message key="title"/></title>
<style>
.error { color: red; }
</style>
</head>
<body>
<h1><fmt:message key="newpatient.registration"/></h1>

<form:form method="post" commandName="newPatientRegistration">
<table width="95%" bgcolor="f8f8ff" border="0" cellspacing="0" cellpadding="5">
<tr>
<td align="right" width="20%">First Name:</td>
<td width="20%">
<form:input path="firstName"/>
</td>
<td width="60%">
<form:errors path="firstName" cssClass="error"/>
</td>
</tr>

<tr>
<td align="right" width="20%">Last Name:</td>
<td width="20%">
<form:input path="lastName"/>
</td>
<td width="60%">
<form:errors path="lastName" cssClass="error"/>
</td>
</tr>
</table>
<input type="submit" align="center" value="Execute">
</form:form>
</body>
</html>


The strange part is that the error indicates the problem about the request attribute in newPatientRegistration bean, but my flow first goes to the 'newPatientRegistration.jsp' through the empty controller 'NewPatientFormController' which does nothing but returns the view as 'newPatientFormTile', which is correctly configured in my tiles definition file named views.xml.
So, in my opinion the flow goes to display 'newPatientRegistration.jsp' does not even involve bean newPatientRegistration bean, but Spring is trying to resolve this bean first somehow.

Any help will be highly appreciated.

Thanks,
Nitin.

nitin.vashi
Dec 7th, 2010, 01:40 PM
I finally was able to get rid of this error.
Actually, there was a flaw in my request processing flow.

I was just trying to forward the request to a view without binding a modle to it, as it wa sjust a display of an html screen.
So, I completely got rid of the intermediate controller, and just gave the path to my actual controller as the hyper link in my jsp, and it worked just fine.

Thanks,
Nitin.