📄 timesheetperiodcontroller.java
字号:
package net.java.workeffort.webapp.action;import java.util.HashMap;import java.util.List;import java.util.Locale;import java.util.Map;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import net.java.workeffort.infrastructure.view.ViewHelper;import net.java.workeffort.service.domain.Timesheet;import net.java.workeffort.service.support.TimesheetUtils;import net.java.workeffort.webapp.support.TimesheetHelper;import org.apache.commons.lang.Validate;import org.springframework.validation.BindException;import org.springframework.web.servlet.ModelAndView;import org.springframework.web.servlet.support.RequestContextUtils;/** * Controller which allows the user to pick the start dates for a new timesheet. * @author Antony Joseph */public class TimesheetPeriodController extends BaseFormController { private TimesheetUtils timesheetUtils; protected void init() { Validate.notNull(getFormView(), "'formView' cannot be null"); Validate.notNull(getSuccessView(), "'successView' cannot be null"); Validate.notNull(timesheetUtils, "'timesheetUtils' cannot be null"); } public void setTimesheetUtils(TimesheetUtils timesheetUtils) { this.timesheetUtils = timesheetUtils; } protected Map referenceData(HttpServletRequest request) throws Exception { if (logger.isDebugEnabled()) logger.info("referenceData invoked."); Locale locale = RequestContextUtils.getLocale(request); String dateFormat = getWebApplicationContext().getMessage("dateFormat", null, locale); List list = timesheetUtils.getTimesheetFromDtLov(dateFormat, locale); Map map = new HashMap(); map.put("fromDtLov", list); return map; } protected Object formBackingObject(HttpServletRequest request) throws Exception { if (logger.isDebugEnabled()) logger.info("formBackingObject() invoked."); Timesheet timesheet = (Timesheet) super.formBackingObject(request); if (isFormSubmission(request)) { // the timesheetCrud.jsp requires the timesheetFormhelper in session // set it here. Only 'user' can create a new timesheet. TimesheetHelper timesheetHelper = new TimesheetHelper(); timesheetHelper.setTimesheetUserType(TimesheetCrudController.USER); request.getSession().setAttribute( TimesheetCrudController.TIMESHEET_HELPER_ATTR, timesheetHelper); } else { Locale locale = RequestContextUtils.getLocale(request); String dateFormat = getWebApplicationContext().getMessage( "dateFormat", null, locale); timesheet.setFromDt(timesheetUtils.getDefaultTimesheetFromDate()); } return timesheet; } protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { if (logger.isInfoEnabled()) logger.info("onSubmit() invoked."); Timesheet timesheet = (Timesheet) command; Locale locale = RequestContextUtils.getLocale(request); String dateFormat = getWebApplicationContext().getMessage("dateFormat", null, locale); timesheet.setPartyCd(getSecurityProfile(request).getPartyCd()); timesheet.setThruDt(timesheetUtils.getTimesheetThruDate(timesheet .getFromDt(), timesheetUtils.getDatesForTimesheet( timesheet.getFromDt(), dateFormat, locale).size())); // create a new token to prevent multiple submissions saveToken(request); saveViewHelper(request, ViewHelper.INSERT_MODE); Map model = new HashMap(); model.put(getCommandName(), timesheet); List datesForTimesheet = timesheetUtils.getDatesForTimesheet(timesheet .getFromDt(), dateFormat, locale); model.put("datesForTimesheet", datesForTimesheet); model.put("noOfDays", new Integer(datesForTimesheet.size())); model.put(BindException.ERROR_KEY_PREFIX + getCommandName(), createNewBindException(request, command, getCommandName())); request.getSession().setAttribute( "FORM.timesheetCrudController.command", timesheet); return new ModelAndView(getSuccessView(), model); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -