List of usage examples for org.springframework.web.bind ServletRequestDataBinder ServletRequestDataBinder
public ServletRequestDataBinder(@Nullable Object target)
From source file:teste.framework.Action.java
public void bind(HttpServletRequest request, Object entity) { ServletRequestDataBinder db = new ServletRequestDataBinder(entity); db.registerCustomEditor(Calendar.class, new CalendarPropertyEditor("yyyy-MM-dd")); db.bind(request);// w w w . j ava2 s . c o m }
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 av a 2s . c om*/ 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);//from 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 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);// www . 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:org.stockwatcher.web.StockController.java
private StockCriteria getCriteria(HttpServletRequest request) { StockCriteria criteria = new StockCriteria(); ServletRequestDataBinder binder = new ServletRequestDataBinder(criteria); binder.registerCustomEditor(Integer[].class, "industryIds", new StringArrayPropertyEditor()); binder.bind(request);//from w w w .jav a2 s . co m return criteria; }
From source file:com.hmsinc.epicenter.webapp.map.MapStylingController.java
/** * @param request/* w ww. j a v a2 s . c o m*/ * @return * @throws ServletException * @throws IOException */ private StyleParameters parse(HttpServletRequest request) throws ServletException, IOException { final AnalysisParametersDTO queryParams = new AnalysisParametersDTO(); final ServletRequestDataBinder binder = new ServletRequestDataBinder(queryParams); binder.registerCustomEditor(DateTime.class, new DateTimePropertyEditor()); binder.registerCustomEditor(Properties.class, new EncodedPropertiesPropertyEditor()); binder.bind(request); Validate.notNull(queryParams, "No parameters were specified"); final AnalysisParameters params = convertParameters(queryParams); Validate.notNull(params); final StyleParameters styleParameters = new StyleParameters(request, params, queryParams, getPrincipal()); logger.trace("Parameters: {}", styleParameters); return styleParameters; }
From source file:org.synyx.hades.extensions.web.PageableArgumentResolver.java
public Object resolveArgument(MethodParameter methodParameter, NativeWebRequest webRequest) { if (methodParameter.getParameterType().equals(Pageable.class)) { assertPageableUniqueness(methodParameter); Pageable request = getDefaultFromAnnotationOrFallback(methodParameter); ServletRequest servletRequest = (ServletRequest) webRequest.getNativeRequest(); PropertyValues propertyValues = new ServletRequestParameterPropertyValues(servletRequest, getPrefix(methodParameter), separator); DataBinder binder = new ServletRequestDataBinder(request); binder.initDirectFieldAccess();/*w w w . ja v a 2 s. c om*/ binder.registerCustomEditor(Sort.class, new SortPropertyEditor("sort.dir", propertyValues)); binder.bind(propertyValues); if (request.getPageNumber() > 0) { request = new PageRequest(request.getPageNumber() - 1, request.getPageSize(), request.getSort()); } return request; } return UNRESOLVED; }
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;//from w ww .jav 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.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;// w w w .ja va 2s .c o 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[] { "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:com.hmsinc.epicenter.webapp.data.DownloadService.java
/** * @param request/*from w w w . j a va 2 s . c o m*/ * @return */ private AnalysisParametersDTO bind(final HttpServletRequest request) { final AnalysisParametersDTO queryParams = new AnalysisParametersDTO(); final ServletRequestDataBinder binder = new ServletRequestDataBinder(queryParams); binder.registerCustomEditor(DateTime.class, new DateTimePropertyEditor()); binder.registerCustomEditor(Properties.class, new EncodedPropertiesPropertyEditor()); binder.bind(request); Validate.notNull(queryParams, "No parameters were specified"); return queryParams; }