Update form: Spring mvc + thymeleaf -


i'm trying create thymeleaf form update couple of attributes of backing object:

@requestmapping(value = "/jobs/{id}", method = requestmethod.get) public modelandview update(@pathvariable integer id ) {     modelandview mav = new modelandview("updatejob.html");     jobdescription updatejob = jobdescriptionservice.findbyid(id);     mav.addobject("updatejob", updatejob);     return mav; }  @requestmapping(value = "/jobs/{id}", method = requestmethod.put) public string saveupdate(@pathvariable integer id, @modelattribute("updatejob") jobdescription updatejob) {     jobdescriptionservice.update(updatejob);     return "redirect:/jobs/" + id; }   <form th:action="@{'/jobs/'+ ${updatejob.id}}" th:object="${updatejob}" th:method="put">     <table>         <tr>             <td><label>description</label></td>             <td><input type="text" th:field="*{description}" /></td>         </tr>         <tr>             <td><label>deadline</label></td>             <td><input type="text" th:field="*{deadline}" /></td>         </tr>         <tr>             <td></td>             <td><button type="submit">update</button></td>         </tr>     </table> </form> 

the problem job object has couple of other attributes(like id, createddate, etc) don't want update. however, when click submit button of update form, object created in saveupdate method has attributes set null(unless set them in hidden fields inside form). there other way keep them?

the safest way load original job object id, , set new values on , update it... like:

jobdescription originaljob = jobdescriptionservice.findbyid(updatejob.getid());  originaljob.setparamforupdate(updatejob.getparamforupdate()); originaljob.setanotherparamforupdate(updatejob.getanotherparamforupdate());  jobdescriptionservice.update(originaljob); 

and save data want keep unchanged...


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -