java - Neither BindingResult nor plain target object for bean name 'categorie' available as request attribute -
i'm new spring mvc , have error form validation , don't know why.
i looked answers related problem on web not figure out problem in code.
here jsp page.
<div class="modal-body"> <f:form method="post" commandname="categorie" enctype="multipart/form-data" action="categorie/add" class="pure-form pure-form-aligned"> <%-- <f:form action="addcategorie" method="post"> --%> <p><label for="nomcategorie">nom catégorie </label><f:input type="text" id="nomcatg" path="nomcategorie"/></p> <p><label for="typecategorie">type catégorie </label><f:input type="text" id="typecatg" path="typecategorie"/></p> <div class="pure-control-group"> <label for="image">image</label> <%-- <c:if test="${famille.idfamille!=null}"> <c:if test="${famille.image!=null}"> <img alt="" src="photofamille?idfam=${famille.idfamille }" class="img"> </c:if> </c:if> --%> <!-- <br> <br> --> <input type="file" name="file" > </div> <br> <div class="pure-control-group"> <label for="couleurfond">couleur de fond</label> <f:input type="color" name="your favourite color" pattern="#[a-f0-9]{9}" value="#fad345" list="" path="couleur"/> <!-- color: <input class="jscolor" value="ab2567"> --> </div> <f:input path="idcategorie" type="text" /> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">close</button> <button type="submit" class="btn btn-primary" >save changes</button> </div> </f:form>
my controller:
@controller public class categoriecontroller { @autowired categorieservice categorieservice; @requestmapping(value = "/categories", method = requestmethod.get) public string liste(model model,httpservletrequest request) { // model.addattribute("article", new article()); model.addattribute("categories", categorieservice.listcategories()); return "listcategories"; } @requestmapping(value= "/categorie/add",method = requestmethod.post,headers="content-type=multipart/*") public string addfamille(@modelattribute("categorie") categorie c,bindingresult bindingresult, model model,multipartfile file) throws exception{ model.addattribute("categorie", new categorie()); if(c.getidcategorie() == null){ categorieservice.addcategorie(c); } return "redirect:/categories"; } }
i found error :
rave: "servlet.service()" pour la servlet jsp lancé une exception java.lang.illegalstateexception: neither bindingresult nor plain target object bean name 'categorie' available request attribute @ org.springframework.web.servlet.support.bindstatus.<init>(bindstatus.java:144) @ org.springframework.web.servlet.tags.form.abstractdataboundformelementtag.getbindstatus(abstractdataboundformelementtag.java:168) @ org.springframework.web.servlet.tags.form.abstractdataboundformelementtag.getpropertypath(abstractdataboundformelementtag.java:188) @ org.springframework.web.servlet.tags.form.abstractdataboundformelementtag.getname(abstractdataboundformelementtag.java:154) @ org.springframework.web.servlet.tags.form.abstractdataboundformelementtag.writedefaultattributes(abstractdataboundformelementtag.java:117) @ org.springframework.web.servlet.tags.form.abstracthtmlelementtag.writedefaultattributes(abstracthtmlelementtag.java:422) @ org.springframework.web.servlet.tags.form.inputtag.writetagcontent(inputtag.java:142) @ org.springframework.web.servlet.tags.form.abstractformtag.dostarttaginternal(abstractformtag.java:84) @ org.springframework.web.servlet.tags.requestcontextawaretag.dostarttag(requestcontextawaretag.java:80) @ org.apache.jsp.web_002dinf.views.listcategories_jsp._jspx_meth_f_005finput_005f0(listcategories_jsp.java:757) @ org.apache.jsp.web_002dinf.views.listcategories_jsp._jspx_meth_f_005fform_005f0(listcategories_jsp.java:683) @ org.apache.jsp.web_002dinf.views.listcategories_jsp._jspservice(listcategories_jsp.java:538) @ org.apache.jasper.runtime.httpjspbase.service(httpjspbase.java:70) @ javax.servlet.http.httpservlet.service(httpservlet.java:727) @ org.apache.jasper.servlet.jspservletwrapper.service(jspservletwrapper.java:432) @ org.apache.jasper.servlet.jspservlet.servicejspfile(jspservlet.java:395) @ org.apache.jasper.servlet.jspservlet.service(jspservlet.java:339) @ javax.servlet.http.httpservlet.service(httpservlet.java:727) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:303) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:208) @ org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:241) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:208) @ org.apache.catalina.core.applicationdispatcher.invoke(applicationdispatcher.java:748) @ org.apache.catalina.core.applicationdispatcher.processrequest(applicationdispatcher.java:486) @ org.apache.catalina.core.applicationdispatcher.doforward(applicationdispatcher.java:411) @ org.apache.catalina.core.applicationdispatcher.forward(applicationdispatcher.java:338) @ org.springframework.web.servlet.view.internalresourceview.rendermergedoutputmodel(internalresourceview.java:168) @ org.springframework.web.servlet.view.abstractview.render(abstractview.java:303) @ org.springframework.web.servlet.dispatcherservlet.render(dispatcherservlet.java:1228) @ org.springframework.web.servlet.dispatcherservlet.processdispatchresult(dispatcherservlet.java:1011) @ org.springframework.web.servlet.dispatcherservlet.dodispatch(dispatcherservlet.java:955) @ org.springframework.web.servlet.dispatcherservlet.doservice(dispatcherservlet.java:877) @ org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:966) @ org.springframework.web.servlet.frameworkservlet.doget(frameworkservlet.java:857) @ javax.servlet.http.httpservlet.service(httpservlet.java:620) @ org.springframework.web.servlet.frameworkservlet.service(frameworkservlet.java:842) @ javax.servlet.http.httpservlet.service(httpservlet.java:727) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:303) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:208) @ org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:241) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:208) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:220) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:122) @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:504) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:170) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:103) @ org.apache.catalina.valves.accesslogvalve.invoke(accesslogvalve.java:950) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:116) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:421) @ org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1074) @ org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:611) @ org.apache.tomcat.util.net.jioendpoint$socketprocessor.run(jioendpoint.java:316) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1145) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:615) @ org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run(taskthread.java:61) @ java.lang.thread.run(thread.java:745) févr. 08, 2016 2:57:15 pm org.apache.catalina.core.standardwrappervalve invoke grave: servlet.service() servlet [appservlet] in context path [/elolink] threw exception [an exception occurred processing jsp page /web-inf/views/listcategories.jsp @ line 417 414: <f:form method="post" commandname="categorie" enctype="multipart/form-data" 415: action="categorie/add" class="pure-form pure-form-aligned"> 416: <%-- <f:form action="addcategorie" method="post"> --%> 417: <p><label for="nomcategorie">nom cat�gorie </label><f:input type="text" id="nomcatg" path="nomcategorie"/></p> 418: <p><label for="typecategorie">type cat�gorie </label><f:input type="text" id="typecatg" path="typecategorie"/></p> 419: <div class="pure-control-group"> 420: <label for="image">image</label>
what's problem ,please me resolve
your jsp looking binding bean called categorie.
can add new bean form in liste
method.
that is, move line method:
model.addattribute("categorie", new categorie());
then, make sure properties on page found in categorie
bean.
also, newer way use modelattribute
instead of commandname
.
you can take @ this post similar situation.
Comments
Post a Comment