Bonjour, j'ai un formulaire que je n'arrive pas a passer a mon controlleur avec les annotations.
Je suis nouveau dans spring et on me demande d'utiliser les annotations de spring 2.5
voici des morceaux de codes pertinents selon moi
/******************JSP***********************/
<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>
/***************CONTROLLEUR*******************/
@Controller
@RequestMapping("/upload.do" )
public class MyController {
@RequestMapping(method = RequestMethod.POST)
public void onSubmit(
@ModelAttribute("myForm" ) MyForm myForm,
HttpServletResponse response) {
//du code utilisant myForm
//retour void car je reecris "HttpServletResponse response" pour telecharger un fichier envoyé par un webservice
}
@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*******************/
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;
}
}
/*****************ERREUR**************************/
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)
/*****************************************************************/
Ca fait un moment que je planche dessus et je vois pas. J'ai essayé pas mal de choses sans resultat.
Merci d'avance pour l'aide
---------------
Toinou87 ;-p May the force be with you!!