I am learning Spring MVC 3 and am not a Java expert in general. I have a few questions
- From what I can tell
ModelAndViewis not used anymore. I also see these two:org.springframework.ui.Modelorg.springframework.ui.ModelMap
What’s the difference between ModelMap and Model? Is one of them old style like ModelAndView?
- How can I pass form data back to the controller? Here’s what I have so far:
VIEW
<form action="/KSC/users/update" method="POST" class="form-horizontal" id="fEdit">
<input type="hidden" id="id" name="id" value="${record.id}" />
<div class="control-group">
<label for="userName" class="control-label"></label>
<div class="controls">
<input type="text" id="userName" name="userName" value="${record.userName}" data-validation-engine="validate[required]" />
</div>
</div>
<div class="control-group">
<label for="email" class="control-label"></label>
<div class="controls">
<input type="text" id="email" name="email" value="${record.email}" data-validation-engine="validate[required,custom[email]]" />
</div>
</div>
<div class="control-group">
<div class="controls">
<input type="submit" value="Save" class="btn btn-primary" />
<a href="/KSC/users" class="btn">Cancel</a>
</div>
</div>
</form>
EDIT ACTION
Here’s what I originally passed to the above View from the Edit action:
@RequestMapping(value = "/users/edit/{id}")
public String edit(ModelMap model, @PathVariable("id") int userId) {
KCSUser user = service.find(userId);
model.addAttribute("record", user);
return "user/edit";
}
CONTROLLER UPDATE ACTION
@RequestMapping(value = "/users/update")
public String update(ModelMap model) {
//TODO
}
I need to access the updated model data so i can save it to my DB. Ideally if it could map directly to a KSCUser object that would be nice.. but if not, then a Model or ModelMap would be fine too. How can I do this?
This seems to work: