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.
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.