Announcement Announcement Module
Collapse
No announcement yet.
Unbound form elements are cleared in the domain upon execute of controller update... Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unbound form elements are cleared in the domain upon execute of controller update...

    My domain model contains a field that I set via a different process and thus I use render="false" disableFormBinding="true" to prevent it from being changed by the UI. However, when the controller receives my object it proceeds to write it to the database, thus overwriting the field I did not set to what ever the default happens to be.

    For example, here is an update method generated by Roo:

    Code:
        
        @RequestMapping(method = RequestMethod.PUT, produces = "text/html")
        public String RoleController.update(@Valid Role role, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
            if (bindingResult.hasErrors()) {
                populateEditForm(uiModel, role);
                return "roles/update";
            }
            uiModel.asMap().clear();
            roleRepository.save(role);
            return "redirect:/roles/" + encodeUrlPathSegment(role.getId().toString(), httpServletRequest);
        }
    As you can see, the data coming from the from is mapped by Spring MVC right on to the domain model Role and that role is saved. I could write the code to instead, find existing role, then move the fields I want persisted and leave the fields I do not want unchanged, but I was wondering if there is an automatic way to do this common task with Roo.

    Also, is there a way to alter roo to tell it to generate these templates differently? Can I change what is generated, completely?

    Thanks.
    -AP_
Working...
X