Rim Bejaoui February 2016

Neither BindingResult nor plain target object for bean name 'categorie' available as request attribute

I'm new to Spring MVC and I have an error with a form validation and I don't know why.

I looked almost all answers related this problem on the web but could not figure out the problem in my code.

Here is my 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">Clos        

Answers


bphilipnyc February 2016

Your JSP is looking for a binding bean called categorie. You can add a new bean to your form in your liste method.

That is, move this line to your GET method:

model.addAttribute("categorie", new Categorie());

Then, make sure all the properties on the page are also found in your Categorie bean.

Also, the newer way to do this is to use modelAttribute instead of commandName.

You can take a look at this post for a similar situation.

Post Status

Asked in February 2016
Viewed 1,699 times
Voted 11
Answered 1 times

Search




Leave an answer