List of usage examples for org.springframework.web.bind ServletRequestDataBinder getBindingResult
public BindingResult getBindingResult()
From source file:common.bind.ABindValidator.java
public BindingResult bindAndValidate(Object command, HttpServletRequest request) { ServletRequestDataBinder binder = new ServletRequestDataBinder(command); initBinder(binder);/*from w ww . j a va 2 s .co m*/ binder.bind(request); BindingResult res = binder.getBindingResult(); validate(command, res, request); return res; }
From source file:gallery.web.controller.pages.types.WallpaperRateType.java
@Override public UrlBean execute(HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws Exception { /** bind command */ WallpaperRating command = new WallpaperRating(); ServletRequestDataBinder binder = new ServletRequestDataBinder(command); binder.setRequiredFields(REQUIRED_FIELDS); binder.bind(request);//ww w . j a va 2 s.c o m BindingResult res = binder.getBindingResult(); int error = '1'; if (res.hasErrors()) { common.CommonAttributes.addErrorMessage("form_errors", request); } else { //correcting rating gallery.web.support.wallpaper.rating.Utils.correctRate(command); command.setIp(request.getRemoteAddr()); if (wallpaperService.getRowCount("id", command.getId_photo()) == 1) { Object[] values = new Object[] { command.getId_photo(), command.getIp() }; if (wallpaperRatingService.getRowCount(RATE_WALLPAPER_WHERE, values) > 0) { common.CommonAttributes.addErrorMessage("duplicate_ip", request); } else { wallpaperRatingService.save(command); common.CommonAttributes.addHelpMessage("operation_succeed", request); error = '0'; } } else { common.CommonAttributes.addErrorMessage("not_exists.wallpaper", request); } } OutputStream os = response.getOutputStream(); os.write(error); os.flush(); return null; }
From source file:gallery.web.controller.resolution.cms.ResolutionCmsDelegate.java
public ModelAndView doMultiUpdate(HttpServletRequest req, HttpServletResponse resp) { //logger.fine("do=multi update"); String action = req.getParameter("action"); if (action != null && action.equals("multiUpdate")) { ResolutionMulti command = new ResolutionMulti(); BindingResult res = null;//w ww . j a v a2s. co m ServletRequestDataBinder binder = new ServletRequestDataBinder(command); binder.bind(req); res = binder.getBindingResult(); if (res.hasErrors()) { common.CommonAttributes.addErrorMessage("form_errors", req); //logger.fine("hasErrors"); } else { int rez = service.updateObjectArrayShortById(new String[] { "width", "height" }, command.getId(), command.getWidth(), command.getHeight()); if (rez > 0) { common.CommonAttributes.addHelpMessage("operation_succeed", req); //logger.fine("not hasErrors"); } else { common.CommonAttributes.addErrorMessage("operation_fail", req); //logger.fine("hasErrors"); } } } //after updating values shoving all pages(doView) return doView(req, resp); }
From source file:gallery.web.controller.resolution.cms.ResolutionCmsDelegate.java
public ModelAndView doInsert(HttpServletRequest req, HttpServletResponse resp/*, Pages command*/) { Map<String, Object> m = getCommonModel(req); m.put(config.getContentUrlAttribute(), insert_url); m.put("editForm_topHeader", ""); String action = req.getParameter(gallery.web.controller.Config.ACTION_PARAM_NAME); Resolution command = new Resolution(); if (action != null && action.equals("insert")) { /** bind command */ ServletRequestDataBinder binder = new ServletRequestDataBinder(command); binder.setRequiredFields(REQUIRED_FIELDS); binder.bind(req);//from w w w . ja v a2 s. c o m BindingResult res = binder.getBindingResult(); validator.validateCMS(command, res); if (res.hasErrors()) { m.put(res.MODEL_KEY_PREFIX + "command", res); m.put("command", command); common.CommonAttributes.addErrorMessage("form_errors", req); } else { service.save(command); m.put("command", command); common.CommonAttributes.addHelpMessage("operation_succeed", req); } } else { m.put("command", command); } return new ModelAndView(config.getTemplateUrl(), m); }
From source file:gallery.web.controller.pages.cms.PagesCmsDelegate.java
public ModelAndView doMultiUpdate(HttpServletRequest req, HttpServletResponse resp) { //logger.fine("do=multi update"); String action = req.getParameter("action"); if ("multiUpdate".equals(action)) { PagesCms command = new PagesCms(); BindingResult res = null;/*ww w. j ava 2s . c om*/ ServletRequestDataBinder binder = new ServletRequestDataBinder(command); binder.bind(req); res = binder.getBindingResult(); if (res.hasErrors()) { common.CommonAttributes.addErrorMessage("form_errors", req); //logger.fine("hasErrors"); } else { int rez = service.updateObjectArrayShortById(new String[] { "sort", "active", "last" }, command.getId(), command.getSort(), command.getActive(), command.getLast()); if (rez > 0) { common.CommonAttributes.addHelpMessage("operation_succeed", req); //logger.fine("not hasErrors"); } else { common.CommonAttributes.addErrorMessage("operation_fail", req); //logger.fine("hasErrors"); } } } //after updating values shoving all pages(doView) return doView(req, resp); }
From source file:gov.nih.nci.cabig.caaers.web.ae.CaptureAdverseEventController.java
/** * If the entry to capture adverse event is from Manage reports, we need to handle the invalid submit case, as it the isFormSubmission is flaged 'true'. *///from w ww. ja va 2 s. c o m @Override protected ModelAndView handleInvalidSubmit(HttpServletRequest request, HttpServletResponse response) throws Exception { String displayReportingPeriod = WebUtils.getStringParameter(request, "displayReportingPeriod"); HttpSession session = request.getSession(); Integer studyId = (Integer) session.getAttribute(SELECTED_STUDY_ID); Integer subjectId = (Integer) session.getAttribute(SELECTED_PARTICIPANT_ID); Integer reportingPeriodId = (Integer) session.getAttribute(SELECTED_COURSE_ID); if (StringUtils.isEmpty(displayReportingPeriod)) { String url = "/pages/ae/captureRoutine?study=" + studyId + "&participant=" + subjectId + "&adverseEventReportingPeriod=" + reportingPeriodId + "&_page=0&_target1=1&displayReportingPeriod=true&addReportingPeriodBinder=true"; return new ModelAndView("redirect:" + url); } //generate the form, validate , processFormSubmission. Object command = formBackingObject(request); ServletRequestDataBinder binder = bindAndValidate(request, command); BindException errors = new BindException(binder.getBindingResult()); return processFormSubmission(request, response, command, errors); }
From source file:com.hihsoft.baseclass.web.controller.BaseController.java
/** * Request. Spring MVCBind?,??/*from w w w .j av a 2 s . c o m*/ * * @return * @see #preBind(HttpServletRequest,Object,ServletRequestDataBinder) */ protected BindingResult bindObject(final HttpServletRequest request, final Object command) throws Exception { Assert.notNull(command); // Binder final ServletRequestDataBinder binder = createBinder(request, command); // ?binder?,?binder? preBind(request, command, binder); // binder.bind(request); // final Validator[] validators = getValidators(); if (validators != null) { for (final Validator validator : validators) { if (validator.supports(command.getClass())) { ValidationUtils.invokeValidator(validator, command, binder.getBindingResult()); } } } return binder.getBindingResult(); }
From source file:no.abmu.abmstatistikk.web.AbstractOrganisationBrowsingController.java
/** * Browse sets up and handles pageHolder browsing of organisationUnits. * /*from w w w .ja v a2 s. c o m*/ * @param request current HTTP request * @param attribute in current HttpSession * @param finderBean specifies which organisationUnits to browse * @param viewName name of the View to render, to be resolved * by the DispatcherServlet's ViewResolver * @return ModelAndView holder for both Model and View in * the web MVC framework to be resolved by a DispatcherServlet. */ private ModelAndView browse(HttpServletRequest request, String attribute, OrgUnitFinderSpecificationBean finderBean, String viewName) { PageHolder pageHolder = (PageHolder) request.getSession(true).getAttribute(attribute); if (null == pageHolder) { pageHolder = browseOrganisationRegisterService.createNewPageHolder(finderBean); if (viewName.equals("kkdBrowseReportingMuseumView")) { pageHolder.setCurrentPageSize(pageHolder.getNrOfElements()); pageHolder.getSort().setProperty("countyNumberAndOrganisationUnitName"); } request.getSession().setAttribute(attribute, pageHolder); } ServletRequestDataBinder binder = new ServletRequestDataBinder(pageHolder, "pageHolder"); binder.bind(request); pageHolder.reload(false); return new ModelAndView(viewName, binder.getBindingResult().getModel()); }
From source file:no.abmu.abmstatistikk.web.AbstractOrganisationBrowsingController.java
/** * Browse children./* w ww . ja va2 s.c om*/ * * @param request current HTTP request * @param attribute in current HttpSession * @param parentOrganisationUnitId * @param viewName name of the View to render, to be resolved * by the DispatcherServlet's ViewResolver * @return ModelAndView holder for both Model and View in * the web MVC framework to be resolved by a DispatcherServlet. */ private ModelAndView browseChildren(HttpServletRequest request, String attribute, Long parentOrganisationUnitId, String viewName) { PageHolderOrganisationUnitImpl pageHolder = (PageHolderOrganisationUnitImpl) request.getSession(true) .getAttribute(attribute); if (null == pageHolder || parentOrganisationUnitId != pageHolder.getWorkingFromOrgUnitId()) { pageHolder = browseOrganisationRegisterService .createNewPageHolderWithChildren(parentOrganisationUnitId); request.getSession().setAttribute(attribute, pageHolder); } ServletRequestDataBinder binder = new ServletRequestDataBinder(pageHolder, "pageHolder"); binder.bind(request); pageHolder.reload(false); return new ModelAndView(viewName, binder.getBindingResult().getModel()); }
From source file:no.abmu.abmstatistikk.web.AbstractStatusBrowsingController.java
/** * Refreshable status browser. /*from w w w. java2s.com*/ * @param request current HTTP request * @param attribute to use store RefreshablePageholder in current http session * @param organisationType name of organisation type * @param schemaType name of schema type * @param view - if sucess use this view as view in ModelAndView * @param year - report year * @return a ModelAndView to render the response */ /* protected ModelAndView countyStatusBrowser( HttpServletRequest request, String attribute, String organisationType, String schemaType, String view, int year) { // This should be replaced with AOP in an XML spring config-file. if (!isSecureContext()) { logger.error("[refreshableCountyStatusBrowser]: no secureContext loging off"); return new ModelAndView(ViewNameConst.LOGOFF_VIEW); } Integer countyNumber = getCountyNumberFromRequestOrLoggedOnUser(request); if (null == countyNumber) { logger.error("[countyStatusBrowser]: could not get any countynumber, return to mainmenu."); return new ModelAndView(ViewNameConst.REDIRECT_2_MAIN_MENU); } OrgUnitFinderSpecificationBean finderBean = new OrgUnitFinderSpecificationBean(); finderBean.setOrganisationTypeName(organisationType); finderBean.setCountyNumber(countyNumber); finderBean.setTodayAsActiveDate(); Map model = statusBrowse(request, attribute, finderBean, schemaType, year); return new ModelAndView(view, model); } */ // //////////////////////////////////////////////////////////////////////// // // Private methods for status browsing // // //////////////////////////////////////////////////////////////////////// protected Map<String, Object> statusBrowse(HttpServletRequest request, String attribute, OrgUnitFinderSpecificationBean finderBean, SchemaTypeNameAndVersion schemaTypeNameAndVersion) { logger.info("Executing statusBrowse"); PageHolder pageHolder = (PageHolder) request.getSession(true).getAttribute(attribute); if (null == pageHolder) { pageHolder = statusReportService.createNewPageHolder(finderBean, schemaTypeNameAndVersion); request.getSession().setAttribute(attribute, pageHolder); } ServletRequestDataBinder binder = new ServletRequestDataBinder(pageHolder, "pageHolder"); binder.bind(request); pageHolder.reload(false); return binder.getBindingResult().getModel(); }