spring - java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'product' available as request attribute -


whenever click on edit button, getting error

java.lang.illegalstateexception: neither bindingresult nor plain target object bean name 'product' available request attribute 

, not able understand what's wrong here

my product controller follows

@requestmapping(value="/product/edit/{id}", method=requestmethod.get) public string editproducts(@pathvariable("id") string productid,model model){     system.out.println("productid");     product = productdao.get(productid);     model.addattribute("product", product);     model.addattribute("productlist",productdao.list());     return "product"; } 

my product.jsp page follows

<c:url var="product" value="/product/add" /> <form:form method="post" commandname="product" action="${product}" enctype="multipart/form-data"> <div class="form-group"> <table class="table table-hover"> <tr>    <td><form:label path="id"><spring:message text="id" /></form:label></td>    <c:choose>    <c:when test="${!empty listvalue.getid()}">    <td><form:input path="id" disabled="true" readonly="true"/></td>    </c:when>    <c:otherwise>    <td><form:input class="form-control" path="id" pattern=".{4,7}" required="true" title="id should contain 4 7 characters" /></td>    </c:otherwise>    </c:choose> </tr> <tr>     <td><form:label path="name">name</form:label></td>     <td><form:input class="form-control" path="name" type="text" required="true"/></td> </tr> <tr>     <td><form:label path="price">price</form:label></td>     <td><form:input class="form-control" path="price" type="text" required="true"/></td> </tr>     <tr>     <td><form:label path="category_id">category id</form:label></td>     <td><form:input class="form-control" path="category_id" type="text" required="true"/></td> </tr>     <tr>     <td><form:label path="supplier_id">supplier id</form:label></td>     <td><form:input class="form-control" path="supplier_id" type="text" required="true"/></td> </tr>  <tr>     <td><form:label path="imge">image</form:label></td>     <td><form:input path="imge" type="file" name="imge" /></td> </tr> <tr>      <td colspan="2"> <c:if test="${!empty productlist.name}"> <input class="btn btn-success" type="submit" value="<spring:message text="edit product"/>"/> </c:if> <c:if test="${empty productlist.name}"> <input class="btn btn-info" type="submit" value="<spring:message text="add product"/>" /> </c:if></td> </tr> </table> <br> </div> </form:form> <center><h1>${msg}</h1></center> <c:if test="${not empty productlist}"> <center><h1>list</h1></center> <table class="table table-hover">     <thead>       <tr>         <th>image</th>         <th>product id</th>         <th>product name</th>         <th>product price</th>         <th>category name</th>         <th>supplier name</th>         <th>action</th>       </tr>     </thead>     <c:foreach var="listvalue" items="${productlist}" varstatus="status">     <tbody>                <tr>                 <td style="width:10% ;height:2%"><img style="width:2% ;height:2%" src='<c:url value="/resources\img/${listvalue.getid()}.jpg"/>'/></td>                                  <td>${listvalue.getid()}</td>                 <td>${listvalue.getname()}</td>                 <td>${listvalue.getprice()}</td>                 <td>                  <c:out  value="${categorylist[status.index]}"/>                  </td>                 <td><c:out  value="${supplierlist[status.index]}"/></td>                 <td><a href="<c:url value='product/edit/${listvalue.getid()}' />" class="btn btn-info">edit</a> / <a href="<c:url value='product/remove/${listvalue.getid()}' /> " class="btn btn-danger">delete</a></td>                </tr>               </c:foreach>         </tbody>   </table>     </c:if> 

i have data populated form when click edit button. newbie , having trouble in section, have viewed similar question, not able understand, please help. if needed more details, i'll provide them well.

you must provide product object jsp can load data. helps when want reload page without loosing data after validating form, instance.

@requestmapping("/newproduct") public modelandview form(@valid product product){     modelandview mv = new modelandview("product");     return mv; } 

Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -