Announcement Announcement Module
Collapse
No announcement yet.
Edit form without data Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Edit form without data

    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>
    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;
    	}
    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", conService.listContactsById(id));
    		return EDIT_VIEW_KEY;
    	}
    Many thanks
    Last edited by zed420; Dec 13th, 2012, 03:00 PM.
Working...
X