Am not sure if this belong here or to JSP forum, mods kindly move it if it does ... thanx
Hi have the this exception, seems my object cannot be found/bound to my form
Stack Trace
SEVERE: Servlet.service() for servlet debugjsp threw exception
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute
at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:141)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:172)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:192)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:158)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.autogenerateId(AbstractDataBoundFormElementTag.java:145)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.resolveId(AbstractDataBoundFormElementTag.java:136)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:120)
at org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:379)
at org.springframework.web.servlet.tags.form.InputTag.writeTagContent(InputTag.java:139)
at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:90)
at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:77)
at org.apache.jsp.jsp.PostProfileForm_jsp._jspx_meth_form_005finput_005f0(PostProfileForm_jsp.java:327)
at org.apache.jsp.jsp.PostProfileForm_jsp._jspx_meth_form_005fform_005f0(PostProfileForm_jsp.java:125)
at org.apache.jsp.jsp.PostProfileForm_jsp._jspService(PostProfileForm_jsp.java:78)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:445)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:379)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:292)
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:240)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:258)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1174)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:901)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:595)
2008/11/07 10:27:25 org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet action threw exception
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute
at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:141)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:172)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:192)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:158)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.autogenerateId(AbstractDataBoundFormElementTag.java:145)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.resolveId(AbstractDataBoundFormElementTag.java:136)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:120)
at org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:379)
at org.springframework.web.servlet.tags.form.InputTag.writeTagContent(InputTag.java:139)
at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:90)
at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:77)
at org.apache.jsp.jsp.PostProfileForm_jsp._jspx_meth_form_005finput_005f0(PostProfileForm_jsp.java:327)
at org.apache.jsp.jsp.PostProfileForm_jsp._jspx_meth_form_005fform_005f0(PostProfileForm_jsp.java:125)
at org.apache.jsp.jsp.PostProfileForm_jsp._jspService(PostProfileForm_jsp.java:78)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:445)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:379)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:292)
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:240)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:258)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1174)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:901)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:595)
JSP
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<html>
<head>
<title>
Object Form
</title>
</head>
<body bgcolor="#ffffff">
<form:form method="post">
<table border="1">
<tr>
<td>ProfileId</td>
<td>
<select name="profileId">
<c:forEach var="postProfile" items="${postProfileList}">
<option value="<c:out value="${postProfile.profileId}" />">
IDNO<c:out value="${postProfile.profileId}" />
</option>
</c:forEach>
</select>
</td>
</tr>
<tr>
<td>PostProfilestatus</td>
<td>
<form:input path="postProfilestatus" />
</td>
</tr>
<tr>
<td>Musterings</td>
<td>
<form:input path="musterings" />
</td>
</tr>
<tr>
<td>Ranks</td>
<td>
<form:input path="ranks"/>
</td>
</tr>
<tr>
<td>UnitCode</td>
<td>
<form:input path="unitCode"/>
</td>
</tr>
<tr>
<td>Statusreason</td>
<td>
<form:input path="statusreason"/>
</td>
</tr>
<tr>
<td>CrtDat</td>
<td>
<form:input path="rtDat"/>
</td>
</tr>
<tr>
<td>CrtId</td>
<td>
<form:input path="crtId"/>
</td>
</tr>
<tr>
<td>ChgDat</td>
<td>
<form:input path="chgDat"/>
</td>
</tr>
<tr>
<td>ChgId</td>
<td>
<form:input path="chgId"/>
</td>
</tr>
<tr>
<td><input type="submit" name="delete" value="Delete"/></td>
<td><input type="submit" name="update" value="Update"/></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="add" value="+ Add +"/></td>
</tr>
</table>
</form:form>
</body>
</html>
Controller class
package com.jobpost.controller;
import java.util.Map;
import java.util.List;
import java.util.HashMap;
import com.jobpost.postprofile.*;
import com.jobpost.service.PostProfileService;
import org.apache.commons.logging.*;
import org.springframework.web.servlet.*;
import org.springframework.web.servlet.mvc.*;
import org.springframework.web.servlet.view.*;
import javax.servlet.http.*;
import javax.servlet.ServletException;
import org.springframework.validation.BindException;
public class PostProfileFormController extends SimpleFormController {
protected final Log logger = LogFactory.getLog(getClass());
private PostProfileService pps;
public PostProfileService getpps() {
return pps;
}
public void setpps(PostProfileService pps) {
this.pps = pps;
}
public ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response, Object cmd,
BindException errors) throws Exception {
logger.debug(
"Entering PostProfileFormController handleRequest method ....");
PostProfiles postProfiles = (PostProfiles) cmd;
if (null != request.getParameter("delete")) {
System.out.println("[Delete] button pressed ... ");
pps.removePostProfiles(postProfiles);
} else if (null != request.getParameter("update")) {
pps.updatePostProfiles(postProfiles);
System.out.println("[Update] button pressed ... ");
} else if (null != request.getParameter("add")) {
pps.insertPostProfiles(postProfiles);
System.out.println("[Add] button pressed ... ");
}
return new ModelAndView(new RedirectView(getSuccessView()));
}
protected Map<String, List<PostProfiles>> referenceData(HttpServletRequest request) throws ServletException {
List<PostProfiles> pplist = pps.getAllPostProfiles();
Map<String, List<PostProfiles>> model = new HashMap<String, List<PostProfiles>>();
model.put("postProfileList", pplist);
/*ModelAndView mav = new ModelAndView();
mav.addObject("postprofiles", pplist);
*/
return model;
}
protected Object formBackingObject(HttpServletRequest request) throws
ServletException {
String id = request.getParameter("id");
if (null != id && !id.equals("")) {
return pps.findPostProfilesById(Long.parseLong(id));
}
return new PostProfiles();
}
}
action-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- Fixed properties -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"><value>org.springframework.web.servlet.view.JstlView</value></property>
<property name="prefix"><value>/jsp/</value></property>
<property name="suffix"><value>.jsp</value></property>
</bean>
<!-- Custom controller objects -->
<bean id="ppController" class="com.jobpost.controller.PostProfileController">
<property name="postProfileService"><ref bean="postProfileService"/> </property>
</bean>
<bean id="ppFormController" class="com.jobpost.controller.PostProfileFormController">
<property name="sessionForm"><value>true</value></property>
<property name="commandName"><value>postprofiles</value></property>
<property name="commandClass"><value>com.jobpost.postprofile.PostProfiles</value></property>
<property name="formView"><value>PostProfileForm</value></property> <!-- Interesting, you cannot add the suffix here, it will append the .jsp -->
<property name="successView"><value>index.html</value></property> <!-- you MUST add the suffix here, otherwise it won't append the suffix itself -->
<property name="pps"><ref bean="postProfileService"/></property>
</bean>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/index.html">ppController</prop>
<!-- <prop key="/refresh.html">ppFormController</prop> -->
<prop key="/PostProfileForm.html">ppFormController</prop>
</props>
</property>
</bean>
</beans>
Please assist?