Hi,
I'm new to spring and I'm asked to do a project with spring annotations.
I have a Form and I'm not able to binds its data. It's been a while now, that I'm looking on the internet but none of the answers I've found were applicable or worked.
Here are the relevant lines of my code
/******************JSP***********************/
Code:<form:form method="post" action="upload.do" enctype="multipart/form-data" modelAttribute="myForm"> <input type="file" name="file"/> enabledBarcodeDecoding<form:checkbox path="myBool"/> <input type="submit"/> </form:form>
/***************CONTROLLER*******************/
Code:@Controller @RequestMapping("/upload.do" ) public class MyController { @RequestMapping(method = RequestMethod.POST) public void onSubmit( @ModelAttribute("myForm" ) MyForm myForm, HttpServletResponse response) { //code using myForm.file & myForm.myBool //I return void because in this controller I use the HTTPServletResponse to download a file given by a web service } @InitBinder public void initBinder(WebDataBinder binder) { // to actually be able to convert Multipart instance to byte[] // we have to register a custom editor binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor()); // now Spring knows how to handle multipart object and convert them } @ModelAttribute("readerExtensionForm" ) public ReaderExtensionForm getReaderExtensionForm() { return new ReaderExtensionForm(); } }
/***************MyForm*******************/
/*****************ERROR**************************/Code:public class MyForm { private byte[] file; private boolean myBool=true; public MyForm() { super(); } public boolean isMyBool() { return myBool; } public void setMyBool(boolean myBool) { this.myBool = myBool; } public void setFile(byte[] file) { this.file = file; } public byte[] getFile() { return file; } }
Code:2009-06-05 11:14:25,113 ERROR org.springframework.web.servlet.tags.form.CheckboxTag - Neither BindingResult nor plain target object for bean name 'myForm' available as request attribute java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'myForm' 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.AbstractCheckedElementTag.autogenerateId(AbstractCheckedElementTag.java:80) at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.resolveId(AbstractDataBoundFormElementTag.java:136) at org.springframework.web.servlet.tags.form.AbstractSingleCheckedElementTag.writeTagContent(AbstractSingleCheckedElementTag.java:81) at org.springframework.web.servlet.tags.form.CheckboxTag.writeTagContent(CheckboxTag.java:51) 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.fileUpload_jsp._jspx_meth_form_005fcheckbox_005f0(fileUpload_jsp.java:190) at org.apache.jsp.fileUpload_jsp._jspx_meth_form_005fform_005f0(fileUpload_jsp.java:112) at org.apache.jsp.fileUpload_jsp._jspService(fileUpload_jsp.java:70) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 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:191) 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:286) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Unknown Source)
/************************************************** ***************/
It's been a while now, and I don't know what else to do. It might be a really stupid error but I don't know spring enough to find it, and reading & re-reading the manual did not help me.
Thanks for helping me !!!


Reply With Quote