All I needed there was <form:hidden path="conId"/> and it's all working fine.
Hi All
Can someone please point me to the right direction, I'm trying to edit a form information. The form displays but it's Empty. Why ??
Code:<form:form id="myForm" modelAttribute="contacts" method="Post" action="contacts.html" commandName="contacts"> <label>First Name<span class="small">Edit your first name</span></label> <form:input path="firstName" /><br> <form:errors path="firstName" cssClass="error" /><br> <label>Last Name<span class="small">Edit your last name</span></label> <form:input path="lastName" /><br> <form:errors path="lastName" cssClass="error" /><br> <button type="submit">Amend</button> </form:form>I'm not sure if I need to use a query in controller in order to get the result I have tried it like so but I get an error.Code:protected static final String EDIT_VIEW_KEY = "editForm"; @Autowired private ContactsService conService; @RequestMapping(value="/edit/{id}", method = RequestMethod.GET) public String showEditForm(@PathVariable("id") Integer id, @ModelAttribute("contacts") Contacts contacts,Model model){ model.addAttribute("contacts", contacts); return EDIT_VIEW_KEY; }
Many thanksCode:protected static final String EDIT_VIEW_KEY = "editForm"; @Autowired private ContactsService conService; @RequestMapping(value="/edit/{id}", method = RequestMethod.GET) public String showEditForm(@PathVariable("id") Integer id, @ModelAttribute("contacts") Contacts contacts,Model model){ model.addAttribute("contacts", conService.listContactsById(id)); return EDIT_VIEW_KEY; }


Reply With Quote