Spring BindingResult Error [duplicate]
I am getting following error message:
java.lang.IllegalStateException: Neither BindingResult
nor plain target object for bean name 'billingInfoCommand'
available as request attribute
My JSP looks like:
<form:form commandName="billingInfoCommand" method="post"
onsubmit="return checkVals()">
My controller looks like:
public class BillingInfoController extends FusionFormController {
protected final Log logger = LogFactory.getLog(getClass());
private FieldAccessService fieldAccessService;
public BillingInfoController(){
setCommandClass(CommonCommand.class);
setCommandName("billingInfoCommand");
}
protected Map referenceData(HttpServletRequest request,Object command, Errors errors) throws Exception {
CommonCommand commonCommand=(CommonCommand)command;
HashMap<String,Object> refDataMap=new HashMap<String,Object>();
refDataMap.put("billingTypes",this.getLookupValsAsMap("getBillingTypes"));
Long stageId=commonCommand.getEmeaMain().getStageId();
refDataMap.put("requiredFields",requiredFields);
return refDataMap;
}
public Object formBackingObject(HttpServletRequest request){
BillingInfo billingInfoObj=null;
Long cepWorkItemNo=null;
CommonCommand billingInfoCommand=new CommonCommand();
try{
cepWorkItemNo=new Long(request.getParameter("cep_work_item_no"));
}catch(NumberFormatException e){
}
if(cepWorkItemNo==null){
billingInfoObj=new BillingInfo();
}else{
billingInfoObj=(BillingInfo)domainService.getDomainObject(BillingInfo.class,cepWorkItemNo);
}
if(billingInfoCommand.getBillingInfo()==null)
billingInfoCommand.setBillingInfo(billingInfoObj);
if(billingInfoCommand.getEmeaMain()==null)
billingInfoCommand.setEmeaMain(emeaMain);
return billingInfoCommand;
}
}
My Pojo class looks like:
public class BillingInfo {
private Integer billingId;
public Integer getBillingId() {
return billingId;
}
public void setBillingId(Integer billingId) {
this.billingId = billingId;
}
}
Note
I have posted only relevant pieces of code here. I am not sure as to why am I getting mentioned error about IllegalStateException and some useful pointers would be appreciated.
Also, what are normal reason for getting Neither BindingResult nor plain target object for bean name x available as request attribute
errors ?
Full Stack Trace
- java.lang.IllegalStateException:
Neither BindingResult nor plain
target object for bean name
'billingInfoCommand' available as
request attribute
java.lang.IllegalStateException: Neither BindingResult nor plain
target object for bean name
'billingInfoCommand' available as
request attribute at
org.springframework.web.servlet.support.BindStatus.(BindStatus.java:148)
at
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:179)
at
org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.resolveCssClass(AbstractHtmlElementTag.java:404)
at
org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:380)
at
org.springframework.web.servlet.tags.form.LabelTag.writeTagContent(LabelTag.java:89)
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.WEB_002dINF.jsp.globalecep.ap.billing_005finfo_jsp._jspx_meth_form_005flabel_005f0(billing_005finfo_jsp.java:1243)
at
org.apache.jsp.WEB_002dINF.jsp.globalecep.ap.billing_005finfo_jsp._jspService(billing_005finfo_jsp.java:363)
at
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
at
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308)
at
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259)
at
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at
org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:659)
at
org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:565)
at
org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:493)
at
org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:965)
at
org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:600)
at
org.apache.struts.tiles.TilesUtilImpl.doInclude(TilesUtilImpl.java:137)
at
org.apache.struts.tiles.TilesUtil.doInclude(TilesUtil.java:177)
at
org.apache.struts.taglib.tiles.InsertTag.doInclude(InsertTag.java:756)
at
org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag(InsertTag.java:881)
at
org.apache.struts.taglib.tiles.InsertTag.doEndTag(InsertTag.java:473)
at
org.apache.jsp.WEB_002dINF.fusion.jsp.tab_005ftemplate_jsp._jspx_meth_tiles_005finsert_005f2(tab_005ftemplate_jsp.java:1807)
at
org.apache.jsp.WEB_002dINF.fusion.jsp.tab_005ftemplate_jsp._jspService(tab_005ftemplate_jsp.java:307)
at
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
at
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308)
at
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259)
at
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at
org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:659)
at
org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:457)
at
org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:395)
at
org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:311)
at
org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:145)
at
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:251)
at
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1144)
at
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:880)
at
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:793)
at
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:476)
at
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:431)
at
javax.servlet.http.HttpServlet.service(HttpServlet.java:627)
at
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:879)
at
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at
java.lang.Thread.run(Thread.java:595)
Servlet Config Mapping File:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<bean id="apbillingInfoController" class="ap.BillingInfoController">
<property name="queryService" ref="queryService" />
<property name="domainService" ref="domainService" />
<property name="formView" value="ap_billinginfo"/>
<property name="validator" ref="apbillingInfoValidator" />
<property name="fieldAccessService" ref="fieldAccessService"/>
</bean>
<bean id="apbillingInfoValidator" class="validator.ap.BillingInfoValidator">
<property name="queryService" ref="queryService" />
</bean>
<bean id="apcompanyBillingInfoController" class="ap.company.COMPANYBillingInfoController">
<property name="commandName" value="companyBillingInfoBean"/>
<property name="commandClass" value="command.ap.company.COMPANYCommonCommand"/>
<property name="queryService" ref="queryService" />
<property name="domainService" ref="domainService" />
<property name="formView" value="ap_companybillinginfo"/>
<property name="validator" ref="apcompanyBillingInfoValidator" />
开发者_如何学运维 <property name="fieldAccessService" ref="fieldAccessService"/>
</bean>
<bean id="apcompanyBillingInfoValidator" class="validator.ap.company.COMPANYBillingInfoValidator">
<property name="fieldAccessService" ref="fieldAccessService"/>
<property name="queryService" ref="queryService" />
</bean>
<property name="mappings">
<props>
<prop key="/ap_billing.htm">apbillingInfoController</prop>
</props>
</property>
</bean>
<property name="mappings">
<props>
<prop key="/company_ap_billing.htm">apcompanyBillingInfoController</prop>
</props>
</property>
</bean>
</beans>
Thanks.
The error itself occurs when your jsp's are rendered. I am assuming you have a jsp with possibly a tag like (spring:bind will cause the same issue)
<form:form modelAttribute="billingInfoCommand">
...
</form:form>
When it renders the jsp, it looks for a bean called billingInfoCommand in your request scope and makes it available for jstl expressions (among other things). When there exists no object in the request scope, the exception youre seeing is thrown.
Edit:
Thats good to see you didnt get any errors from removing all your code. Next thing now, try looking at the request scope directly.
<div>The request scope is: ${requestScope}</div>
<div>The command is: ${requestScope.billingInfoCommand}</div>
If you see something like
The request scope is: javax.servlet.jsp.el.ImplicitObjectELResolver......
The command is:
Then the your bean is not actually in the request scope. The next thing you have to look at is where does the backing object get put into the request scope. First thought is that formBackingObject method may have something to do with getting it into the request.
This appears to be an incorrect controller/view wiring. I say that because I see no reference to the BilingInfoController in your stack trace. There should at least be a reference to that controller for the handleRequest/Internal to load the formBackingObject.
Make sure you are setting the bind object or the Display object in the request using
and this should be placed before the Binding Object is used or before any include jsp tags as below
精彩评论