@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; }
private void populateObjects(List<Worklog> worklog, String user, String date) { for (Worklog log : worklog) { log.setModule(dataHolder.getModule(log.getModuleString())); log.setStatus(dataHolder.getStatus(log.getStatusString())); log.setClient(dataHolder.getClient(log.getClientString())); log.setActivity(dataHolder.getActivity(log.getActivityString())); log.setActivityType(dataHolder.getActivityType(log.getActivityTypeSting())); log.setPerson(dataHolder.getPerson(user)); try { if (!date.equals("")) { log.setDate(dataHolder.getDateFormat("MM-dd-yyyy").parse(date)); } else { log.setDate(new Date(System.currentTimeMillis())); } } catch (ParseException e) { e.printStackTrace(); } } }
@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; }