List of usage examples for org.springframework.web.bind ServletRequestDataBinder setRequiredFields
public void setRequiredFields(@Nullable String... requiredFields)
From source file:org.jasig.cas.services.web.RegisteredServiceSimpleFormController.java
/** * Sets the require fields and the disallowed fields from the * HttpServletRequest.//from w w w.ja v a 2 s . c o m * * @see org.springframework.web.servlet.mvc.BaseCommandController#initBinder(javax.servlet.http.HttpServletRequest, * org.springframework.web.bind.ServletRequestDataBinder) */ protected final void initBinder(final HttpServletRequest request, final ServletRequestDataBinder binder) throws Exception { binder.setRequiredFields(new String[] { "description", "serviceId", "name", "allowedToProxy", "enabled", "ssoEnabled", "anonymousAccess", "evaluationOrder" }); binder.setDisallowedFields(new String[] { "id" }); binder.registerCustomEditor(String.class, new StringTrimmerEditor(true)); }
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);// w ww. j a va2s . com 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:common.bind.CommonBindValidator.java
/** * an empty method// w w w. j a v a 2s . c o m * @param binder */ @Override protected void initBinder(ServletRequestDataBinder binder) { binder.setBindEmptyMultipartFiles(false); binder.setRequiredFields(required_fields); binder.setAllowedFields(allowed_fields); binder.setFieldMarkerPrefix("_"); binder.setFieldDefaultPrefix("!"); if (editors != null) { Iterator<Entry<String, PropertyEditor>> i = editors.entrySet().iterator(); while (i.hasNext()) { Entry<String, PropertyEditor> e = i.next(); binder.registerCustomEditor(String.class, e.getKey(), e.getValue()); } } binder.registerCustomEditor(String.class, new StringTrimmerEditor(false)); }
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 ww w . j a v a 2 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:com.baosight.buapx.web.BuapxServiceValidateController.java
protected void initBinder(final HttpServletRequest request, final ServletRequestDataBinder binder) { binder.setRequiredFields("renew"); }
From source file:net.unicon.cas.mfa.web.MultiFactorServiceValidateController.java
/** * Initialize the binder with the required fields. * @param request the request object/*from w w w . j a v a 2 s . c om*/ * @param binder the binder instance */ protected final void initBinder(final HttpServletRequest request, final ServletRequestDataBinder binder) { binder.setRequiredFields("renew"); }
From source file:org.sakaiproject.metaobj.utils.mvc.impl.servlet.FormControllerImpl.java
/** * Set up a custom property editor for the application's date format. *///from w ww. j a va 2 s. c o m protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) { for (Iterator i = getCustomTypedEditors().iterator(); i.hasNext();) { TypedPropertyEditor editor = (TypedPropertyEditor) i.next(); binder.registerCustomEditor(editor.getType(), editor); } if (getRequiredFields() != null) { binder.setRequiredFields(getRequiredFields()); } }