@InitBinder public void initBinder(WebDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); }
@Override public void initBinder(WebDataBinder dataBinder, @RequestParam("datePattern") String thePattern) { CustomDateEditor dateEditor = new CustomDateEditor(new SimpleDateFormat(thePattern), false); dataBinder.registerCustomEditor(Date.class, dateEditor); }
@Override public void initBinder(WebDataBinder dataBinder, @RequestParam("datePattern") String thePattern) { CustomDateEditor dateEditor = new CustomDateEditor(new SimpleDateFormat(thePattern), false); dataBinder.registerCustomEditor(Date.class, dateEditor); }
@Override public void initBinder(WebDataBinder dataBinder, @RequestParam("datePattern") String thePattern) { CustomDateEditor dateEditor = new CustomDateEditor(new SimpleDateFormat(thePattern), false); dataBinder.registerCustomEditor(Date.class, dateEditor); }
@Override public void initBinder(WebDataBinder dataBinder, @RequestParam("datePattern") String thePattern) { CustomDateEditor dateEditor = new CustomDateEditor(new SimpleDateFormat(thePattern), false); dataBinder.registerCustomEditor(Date.class, dateEditor); }
@Override public void initBinder(WebDataBinder dataBinder, @RequestParam("datePattern") String pattern) { CustomDateEditor dateEditor = new CustomDateEditor(new SimpleDateFormat(pattern), false); dataBinder.registerCustomEditor(Date.class, dateEditor); }
@InitBinder public void initBinder(WebDataBinder binder, @RequestParam("date-pattern") Optional<String> optionalPattern) { optionalPattern.ifPresent(pattern -> { CustomDateEditor dateEditor = new CustomDateEditor(new SimpleDateFormat(pattern), false); binder.registerCustomEditor(Date.class, dateEditor); }); }
@InitBinder public void initBinder(WebDataBinder dataBinder, @RequestParam("datePattern") String pattern) { CustomDateEditor dateEditor = new CustomDateEditor(new SimpleDateFormat(pattern), false); dataBinder.registerCustomEditor(Date.class, dateEditor); }
@Override @InitBinder public void initBinder(WebDataBinder dataBinder, @RequestParam("datePattern") String thePattern) { CustomDateEditor dateEditor = new CustomDateEditor(new SimpleDateFormat(thePattern), false); dataBinder.registerCustomEditor(Date.class, dateEditor); }
@InitBinder public void initBinder(WebDataBinder dataBinder, @RequestParam("datePattern") String thePattern) { CustomDateEditor dateEditor = new CustomDateEditor(new SimpleDateFormat(thePattern), false); dataBinder.registerCustomEditor(Date.class, dateEditor); }
@InitBinder("dateParam") public void initBinder(WebDataBinder dataBinder, @RequestParam("datePattern") String datePattern) { SimpleDateFormat dateFormat = new SimpleDateFormat(datePattern); dataBinder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false)); }
@InitBinder public void initBinder(WebDataBinder binder) { binder.initBeanPropertyAccess(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false)); }
@InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor(String.class, new StringMultipartFileEditor()); }
@InitBinder public void initBinder(WebDataBinder binder, @PathVariable("hotel") String hotel) { assertEquals("Invalid path variable value", "42", hotel); binder.initBeanPropertyAccess(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false)); }
@Override public void initBinder(WebDataBinder binder) { LocalValidatorFactoryBean vf = new LocalValidatorFactoryBean(); vf.afterPropertiesSet(); binder.setValidator(vf); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false)); } }
@InitBinder public void initBinder(WebDataBinder binder) { binder.initBeanPropertyAccess(); binder.registerCustomEditor(Map.class, new CustomMapEditor()); }
@InitBinder({"myCommand", "date"}) public void initBinder(WebDataBinder binder, String date, @RequestParam("date") String[] date2) { LocalValidatorFactoryBean vf = new LocalValidatorFactoryBean(); vf.afterPropertiesSet(); binder.setValidator(vf); assertEquals("2007-10-02", date); assertEquals(1, date2.length); assertEquals("2007-10-02", date2[0]); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false)); } }
@InitBinder public void initBinder(WebDataBinder binder) { binder.initBeanPropertyAccess(); binder.setRequiredFields("sex"); LocalValidatorFactoryBean vf = new LocalValidatorFactoryBean(); vf.afterPropertiesSet(); binder.setValidator(vf); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false)); }
@Test // SPR-10578 public void missingRequestParamEmptyValueConvertedToNull() throws Exception { WebDataBinder binder = new WebRequestDataBinder(null); binder.registerCustomEditor(String.class, new StringTrimmerEditor(true)); WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class); given(binderFactory.createBinder(webRequest, null, "stringNotAnnot")).willReturn(binder); request.addParameter("stringNotAnnot", ""); MethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(String.class); Object arg = resolver.resolveArgument(param, null, webRequest, binderFactory); assertNull(arg); }
@Test public void missingRequestParamEmptyValueNotRequired() throws Exception { WebDataBinder binder = new WebRequestDataBinder(null); binder.registerCustomEditor(String.class, new StringTrimmerEditor(true)); WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class); given(binderFactory.createBinder(webRequest, null, "name")).willReturn(binder); request.addParameter("name", ""); MethodParameter param = this.testMethod.annot(requestParam().notRequired()).arg(String.class); Object arg = resolver.resolveArgument(param, null, webRequest, binderFactory); assertNull(arg); }