org.springframework.web.bind.annotation.InitBinder Java Examples
The following examples show how to use
org.springframework.web.bind.annotation.InitBinder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TodoController.java From pcf-crash-course-with-spring-boot with MIT License | 5 votes |
@InitBinder public void initBinder(WebDataBinder binder) { // Date - dd/MM/yyyy SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); binder.registerCustomEditor(Date.class, new CustomDateEditor( dateFormat, false)); }
Example #2
Source File: StaffController.java From SA47 with The Unlicense | 5 votes |
@InitBinder("course") private void initCourseBinder(WebDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false)); binder.addValidators(cValidator); }
Example #3
Source File: RequestMappingDataBindingIntegrationTests.java From spring-analysis-note with MIT License | 5 votes |
@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); }); }
Example #4
Source File: UriTemplateServletAnnotationControllerHandlerMethodTests.java From java-technology-stack with MIT License | 5 votes |
@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)); }
Example #5
Source File: UserAdminController.java From Roothub with GNU Affero General Public License v3.0 | 5 votes |
/** * 局部日期转换,将 String 类型的时间数据转化为 Date 类型 * @param binder * @param request */ @InitBinder public void initBinder(WebDataBinder binder, WebRequest request) { // 转换日期 注意这里的转化要和传进来的字符串的格式一直 如2015-9-9 就应该为yyyy-MM-dd DateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd"); // CustomDateEditor为自定义日期编辑器 binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); }
Example #6
Source File: BaseController.java From jeewx with Apache License 2.0 | 5 votes |
/** * 将前台传递过来的日期格式的字符串,自动转化为Date类型 * * @param binder */ @InitBinder public void initBinder(ServletRequestDataBinder binder) { // SimpleDateFormat dateFormat = new SimpleDateFormat( // "yyyy-MM-dd hh:mm:ss"); // binder.registerCustomEditor(Date.class, new CustomDateEditor( // dateFormat, true)); binder.registerCustomEditor(Date.class, new DateConvertEditor()); }
Example #7
Source File: ServletAnnotationControllerHandlerMethodTests.java From java-technology-stack with MIT License | 5 votes |
@Override @InitBinder public void initBinder(@RequestParam("param1") String p1, @RequestParam(value="paramX", required=false) String px, int param2) { assertNull(px); }
Example #8
Source File: ServletAnnotationControllerHandlerMethodTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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)); }
Example #9
Source File: ServletAnnotationControllerTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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)); }
Example #10
Source File: HttpValidator.java From chassis with Apache License 2.0 | 5 votes |
@InitBinder public void initBinder(WebDataBinder binder) { binder.setValidator(new SpringValidatorAdapter(messageValidator)); }
Example #11
Source File: ServletAnnotationControllerHandlerMethodTests.java From spring-analysis-note with MIT License | 5 votes |
@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)); }
Example #12
Source File: ServletAnnotationControllerHandlerMethodTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@SuppressWarnings("unused") @InitBinder({"myCommand", "date"}) private 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)); }
Example #13
Source File: ValidatorAdvice.java From springlets with Apache License 2.0 | 5 votes |
/** * Adds the {@link CollectionValidator} to the supplied {@link WebDataBinder} * * @param binder web data binder. */ @InitBinder public void initBinder(WebDataBinder binder) { Object target = binder.getTarget(); if (target != null && collectionValidator.supports(target.getClass())) { binder.addValidators(collectionValidator); } }
Example #14
Source File: BaseController.java From DimpleBlog with Apache License 2.0 | 5 votes |
/** * 将前台传递过来的日期格式的字符串,自动转化为Date类型 */ @InitBinder public void initBinder(WebDataBinder binder) { // Date 类型转换 binder.registerCustomEditor(Date.class, new PropertyEditorSupport() { @Override public void setAsText(String text) { setValue(DateUtils.parseDate(text)); } }); }
Example #15
Source File: CrudControllerAdvice.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
@InitBinder protected void initBinder( WebDataBinder binder ) { binder.registerCustomEditor( Date.class, new PropertyEditorSupport() { @Override public void setAsText( String value ) throws IllegalArgumentException { setValue( DateUtils.parseDate( value ) ); } } ); }
Example #16
Source File: ServletAnnotationControllerHandlerMethodTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@SuppressWarnings("unused") @InitBinder private 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)); }
Example #17
Source File: HandlerMethodInvoker.java From lams with GNU General Public License v2.0 | 5 votes |
protected void initBinder(Object handler, String attrName, WebDataBinder binder, NativeWebRequest webRequest) throws Exception { if (this.bindingInitializer != null) { this.bindingInitializer.initBinder(binder, webRequest); } if (handler != null) { Set<Method> initBinderMethods = this.methodResolver.getInitBinderMethods(); if (!initBinderMethods.isEmpty()) { boolean debug = logger.isDebugEnabled(); for (Method initBinderMethod : initBinderMethods) { Method methodToInvoke = BridgeMethodResolver.findBridgedMethod(initBinderMethod); String[] targetNames = AnnotationUtils.findAnnotation(initBinderMethod, InitBinder.class).value(); if (targetNames.length == 0 || Arrays.asList(targetNames).contains(attrName)) { Object[] initBinderArgs = resolveInitBinderArguments(handler, methodToInvoke, binder, webRequest); if (debug) { logger.debug("Invoking init-binder method: " + methodToInvoke); } ReflectionUtils.makeAccessible(methodToInvoke); Object returnValue = methodToInvoke.invoke(handler, initBinderArgs); if (returnValue != null) { throw new IllegalStateException( "InitBinder methods must not have a return value: " + methodToInvoke); } } } } } }
Example #18
Source File: ControllerAdviceTests.java From java-technology-stack with MIT License | 4 votes |
@InitBinder public void initDataBinder(WebDataBinder dataBinder) { if (this.validator != null) { dataBinder.addValidators(this.validator); } }
Example #19
Source File: HiscoreController.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
@InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor(HiscoreEndpoint.class, new HiscoreEndpointEditor()); }
Example #20
Source File: RequestMappingHandlerAdapterIntegrationTests.java From java-technology-stack with MIT License | 4 votes |
@InitBinder("dateParam") public void initBinder(WebDataBinder dataBinder, @RequestParam("datePattern") String datePattern) { SimpleDateFormat dateFormat = new SimpleDateFormat(datePattern); dataBinder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false)); }
Example #21
Source File: TodoController.java From SpringMvcStepByStep with MIT License | 4 votes |
@InitBinder protected void initBinder(WebDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); binder.registerCustomEditor(Date.class, new CustomDateEditor( dateFormat, false)); }
Example #22
Source File: ServletAnnotationControllerTests.java From spring4-understanding with Apache License 2.0 | 4 votes |
@InitBinder public void initBinder(WebDataBinder binder) { binder.initBeanPropertyAccess(); binder.registerCustomEditor(Map.class, new CustomMapEditor()); }
Example #23
Source File: GlobalHandler.java From java-master with Apache License 2.0 | 4 votes |
@InitBinder protected void initBinder(WebDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false)); }
Example #24
Source File: PizzaBuilderController.java From pizzeria with MIT License | 4 votes |
@InitBinder("pizzaBuilderForm") public void initBinder(WebDataBinder webDataBinder) { webDataBinder.addValidators(pizzaBuilderFormValidator); }
Example #25
Source File: UserController.java From AIDR with GNU Affero General Public License v3.0 | 4 votes |
@InitBinder public void initBinder(WebDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); }
Example #26
Source File: CollectionController.java From AIDR with GNU Affero General Public License v3.0 | 4 votes |
@InitBinder public void initBinder(WebDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); }
Example #27
Source File: DateConverter.java From QiQuYingServer with Apache License 2.0 | 4 votes |
@InitBinder public void initBinder(WebDataBinder binder, WebRequest request) { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); df.setLenient(true); binder.registerCustomEditor(Date.class, new CustomDateEditor(df, true)); }
Example #28
Source File: ServletAnnotationControllerTests.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override @InitBinder public void initBinder(@RequestParam("param1") String p1, @RequestParam(value="paramX", required=false) String px, int param2) { assertNull(px); }
Example #29
Source File: WorkflowController.java From openemm with GNU Affero General Public License v3.0 | 4 votes |
@InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor(WorkflowDependencyType.class, new IntEnumEditor<>(WorkflowDependencyType.class)); }
Example #30
Source File: BaseController.java From wenku with MIT License | 4 votes |
/** * 绑定字符过滤编辑器 * @param binder */ @InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor(String.class, new StringEscapeEditor(true));// html转义 }