I have a controller with a GET method written like so:
@Controller
public class ThingController {
@RequestMapping( value = "/Thing.html", method = RequestMethod.GET )
public String editThing(@RequestParam( "thingId" ) String thingId, @ModelAttribute ThingBean thing, BindingResult result) {
thing = <some service call using thingId>
logger.debug("The thing to edit is {}", thingBean);
return "thing/edit";
}
}
The bean is correct (getters and setters), the service call returns the correct ThingBean with the thingId, and my JSP page at thing/edit.jsp shows up.
The JSP is:
<html>
<body>
<h1 id="title" class="title">Edit Thing</h1>
<form:form id="thing" modelAttribute="thing">
<form:input path="subject" id="subject" tabindex="1" />
<form:textarea path="message" />
</form:form>
</body>
</html>
Yet, the JSP displays blank values for the subject and message. Yes, there are getters/setters on those properties.
I have a very similar Controller that works just fine, except there is no @RequestParam in the signature of the GET - mapped method there.
I've not seen anywhere in the Spring WebMVC docs that says I can't do this - why isn't it working? Why isn't the updated ModelAttribute object being bound into the JSP form?
EDIT:
This controller, and this same pattern for GET calls has worked many many different places -- the variable annotated with @ModelAttribute is filled in by the method then available for the JSP page to display. Why, by adding a @RequestParam annotation, does it stop?
@RequestMapping( value = "/Things.html", method = RequestMethod.GET )
public String getThings(@ModelAttribute ThingForm thingForm, BindingResult result) {
try {
// need to get list of Things
List<Thing> Things = <service call that gets list of Things>;
thingForm.setThings(Things);
logger.debug("Things are {}", Things);
}
catch (ResourceNotFoundException e) {
return "error";
}
logger.debug("Thing list loading - end");
// Go to jsp
return "thing/list";
}