@RequestMapping(method = RequestMethod.GET) public ModelAndView initializeForm(@PathVariable("user") String user) { WorklogWrapper worklogWrapper = new WorklogWrapper(); worklogWrapper.getWorklog().add(new Worklog()); ModelAndView modelAndView = dataHolder.getModelAndView("addworklog"); modelAndView.addObject("statuses", dataHolder.getStatuses()); modelAndView.addObject("activities", dataHolder.getActivities()); modelAndView.addObject("activityTypes", dataHolder.getActivityTypes()); modelAndView.addObject("clients", dataHolder.getClients()); modelAndView.addObject("modules", dataHolder.getModules()); modelAndView.addObject("persons", dataHolder.getPersons()); modelAndView.addObject("worklogWrapper", worklogWrapper); return modelAndView; }
@RequestMapping(method = RequestMethod.POST) public ModelAndView submitWorklog( @ModelAttribute("worklogWrapper") WorklogWrapper worklogWrapper, BindingResult errors, @PathVariable("user") String user, @RequestParam(value = "date", defaultValue = "") String date) { if (errors.hasErrors()) { List<ObjectError> l = errors.getAllErrors(); for (ObjectError ob : l) { System.out.println("------ " + ob.getDefaultMessage()); } } populateObjects(worklogWrapper.getWorklog(), user, date); worklogService.addWorklog(worklogWrapper.getWorklog()); ModelAndView modelAndView = dataHolder.getModelAndView("redirect:/spring/" + user + "/showWorklog"); return modelAndView; }