public void onBindOnNewForm(Model model, RequestContext requestContext, Object command) throws Exception { ScheduleForm scheduleForm = (ScheduleForm) command; String schedulePkStr = requestContext.getParameter("schedulePk"); Long schedulePk = LongConvertor.getLongFromString(schedulePkStr); if (schedulePk != null) { Schedule schedule = getScheduleLogic().get(schedulePk); ScheduleHelper.entityToForm(schedule, scheduleForm); } }
@SuppressWarnings("unchecked") public ModelAndView onSubmit( Model model, RequestContext requestContext, Object command, BindException errors) throws Exception { int action = getAction(); String view = getSuccessView(); if (action == ACTION_SAVE) { ScheduleForm scheduleForm = (ScheduleForm) command; // pk must be set, if not than it is real error Long schedulePk = LongConvertor.getLongFromString(scheduleForm.getPk()); if (schedulePk == null) { return createModelAndView(getErrorView()); } // at first load old (for unsetable attributes from form, but not-null) Schedule schedule = getScheduleLogic().get(schedulePk); // fill entity acording to form ScheduleHelper.formToEntity(scheduleForm, schedule); // get current employee Employee employee = getSecurityLogic().getLoggedEmployee(); schedule.setEmployee(employee); getScheduleLogic().store(schedule); // some errors encountered -> do not save and show form view if (requestContext.getErrors().size() > 0) { model.put("scheduleForm", scheduleForm); prepareTypes(model); return createModelAndView(model, getFormView()); } requestContext.addRedirectIgnoreInfo(new Message("schedule.updated")); } return createModelAndView(view); }