Hey all,
I have a form which is used to edit an object. The form does not contain very attribute in the object. My problem is that when I submit my form, any attribute of my object that does not have a corresponding request parameter gets set to NULL when the object is saved?
Is there a way around this? I do not want to have to fill my form with hidden input fields for those object attributes which I don't want the user to be able to edit simply to prevent them from being set to NULL.
My annotated controller:
Thanks in advanceCode:@Controller @RequestMapping("/task/taskEdit.htm") public class TaskEditController { private TaskService taskService; private UserService userService; private TaskValidator validator; @Autowired public TaskEditController(TaskService taskService, TaskValidator validator) { this.taskService = taskService; this.validator = validator; } @InitBinder public void initBinder(WebDataBinder dataBinder) { SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM-yy HH:mm"); dataBinder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false)); } @RequestMapping(method = RequestMethod.GET) public String setupForm(@RequestParam(required = true, value = "id") String id, ModelMap model) { AssignmentTask task = (AssignmentTask) taskService.findById(Long.parseLong(id)); model.addAttribute("task", task); return "/ticket/taskEdit"; } @RequestMapping(method = RequestMethod.POST) public String processSubmit(@ModelAttribute("task") AssignmentTask task, BindingResult result, HttpServletRequest request) { validator.validate(task, result); if(result.hasErrors()) { return "/ticket/taskEdit"; } else { task.setUpdateUser(userService.getCurrentUser()); task.setUpdatedTime(new Date()); taskService.save(task); } return "status/success"; } }![]()


Reply With Quote
