views:

24

answers:

1

I have a standard form controller to update a google protocol buffers message object that gets persisted. For the form I add the Message.Builder to the ModelMap so that I have access to the setter message. However, the values I change in the form are not automatically bound to the Builder object. I can not figure out why that doesn't work... I do have the message in the @SessionAttributes. Below is a summerized version of my implementation.

@RequestMapping(method = RequestMethod.GET)
public String setup(ModelMap modelMap) {
   Message.Builder builder = Message.Builder.newBuilder(serviceLayer.getMessage(someId));
   modelMap.addAttribute("message", builder);
   return "form";
}

@RequestMapping(method = RequestMethod.POST)
public String process(@ModelAttribute("message") Message message) {
   serviceLayer.saveMessage(message.build());
   return "done";
}
A: 

Turns out Messages embedded the getter methods only return an immutable object even from the Builder. Instead I had to reconstruct the Message from bottom up using the HttpServletRequest.

predhme