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 Project: spring-analysis-note Author: Vip-Augus File: RequestMappingDataBindingIntegrationTests.java License: 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 #2
Source Project: SA47 Author: suriarasai File: StaffController.java License: 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 Project: Roothub Author: miansen File: UserAdminController.java License: 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 #4
Source Project: spring4-understanding Author: langtianya File: ServletAnnotationControllerTests.java License: 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 #5
Source Project: spring-analysis-note Author: Vip-Augus File: ServletAnnotationControllerHandlerMethodTests.java License: 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 #6
Source Project: spring4-understanding Author: langtianya File: ServletAnnotationControllerHandlerMethodTests.java License: 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 #7
Source Project: dhis2-core Author: dhis2 File: CrudControllerAdvice.java License: 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 #8
Source Project: pcf-crash-course-with-spring-boot Author: in28minutes File: TodoController.java License: 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 #9
Source Project: spring4-understanding Author: langtianya File: ServletAnnotationControllerHandlerMethodTests.java License: 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 #10
Source Project: lams Author: lamsfoundation File: HandlerMethodInvoker.java License: 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 #11
Source Project: springlets Author: DISID File: ValidatorAdvice.java License: 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 #12
Source Project: DimpleBlog Author: DimpleFeng File: BaseController.java License: 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 #13
Source Project: spring4-understanding Author: langtianya File: ServletAnnotationControllerHandlerMethodTests.java License: 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 #14
Source Project: java-technology-stack Author: codeEngraver File: UriTemplateServletAnnotationControllerHandlerMethodTests.java License: 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 #15
Source Project: jeewx Author: zhangdaiscott File: BaseController.java License: 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 #16
Source Project: java-technology-stack Author: codeEngraver File: ServletAnnotationControllerHandlerMethodTests.java License: 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 #17
Source Project: spring4-understanding Author: langtianya File: ServletAnnotationControllerTests.java License: Apache License 2.0 | 4 votes |
@InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEditor(String.class, new StringMultipartFileEditor()); }
Example #18
Source Project: airsonic-advanced Author: airsonic-advanced File: UserSettingsController.java License: GNU General Public License v3.0 | 4 votes |
@InitBinder protected void initBinder(WebDataBinder binder, HttpServletRequest request) { binder.addValidators(new UserSettingsValidator(securityService, settingsService, request)); }
Example #19
Source Project: zuihou-admin-cloud Author: zuihou File: IndexController.java License: Apache License 2.0 | 4 votes |
@InitBinder public void initBinder(WebDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat(DEFAULT_DATE_TIME_FORMAT); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); }
Example #20
Source Project: spring-analysis-note Author: Vip-Augus File: ModelInitializerTests.java License: MIT License | 4 votes |
@InitBinder public void initDataBinder(WebDataBinder dataBinder) { if (this.validator != null) { dataBinder.addValidators(this.validator); } }
Example #21
Source Project: spring4-understanding Author: langtianya File: Portlet20AnnotationControllerTests.java License: Apache License 2.0 | 4 votes |
@InitBinder({"myCommand", "date"}) private void initBinder(WebDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false)); }
Example #22
Source Project: spring-analysis-note Author: Vip-Augus File: InitBinderBindingContextTests.java License: MIT License | 4 votes |
@InitBinder public void initBinderTypeConversion(WebDataBinder dataBinder, @RequestParam int requestParam) { dataBinder.setDisallowedFields("requestParam-" + requestParam); }
Example #23
Source Project: spring4-understanding Author: langtianya File: HandlerMethodResolver.java License: Apache License 2.0 | 4 votes |
protected boolean isInitBinderMethod(Method method) { return AnnotationUtils.findAnnotation(method, InitBinder.class) != null; }
Example #24
Source Project: onboard Author: sercxtyf File: NewInvitationController.java License: Apache License 2.0 | 4 votes |
@InitBinder protected void initRegistrationBinder(WebDataBinder binder) { binder.setValidator(validator); }
Example #25
Source Project: spring-analysis-note Author: Vip-Augus File: ControllerMethodResolverTests.java License: MIT License | 4 votes |
@InitBinder void initDataBinder() {}
Example #26
Source Project: spring-analysis-note Author: Vip-Augus File: RequestMappingHandlerAdapterIntegrationTests.java License: 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 #27
Source Project: springMvc4.x-project Author: longjiazuo File: ExceptionHandlerAdvice.java License: Apache License 2.0 | 4 votes |
@InitBinder //④ public void initBinder(WebDataBinder webDataBinder) { webDataBinder.setDisallowedFields("id"); //⑤ }
Example #28
Source Project: egeria Author: odpi File: OpenLineageController.java License: Apache License 2.0 | 4 votes |
/** * This method is registering a custom converter for View and Scope enums in order to be able to use in url the text of the enum and not the actual name * @param webdataBinder DataBinder for data binding from web request parameters to JavaBean objects */ @InitBinder public void initBinder(final WebDataBinder webdataBinder) { webdataBinder.registerCustomEditor(Scope.class, new ScopeEnumConverter()); }
Example #29
Source Project: DevOps-for-Web-Development Author: PacktPublishing File: VisitController.java License: MIT License | 4 votes |
@InitBinder public void setAllowedFields(WebDataBinder dataBinder) { dataBinder.setDisallowedFields("id"); }
Example #30
Source Project: maven-framework-project Author: v5developer File: ProductController.java License: MIT License | 4 votes |
@InitBinder public void initialiseBinder(WebDataBinder binder) { binder.setAllowedFields("productId","name","unitPrice","description","manufacturer","category","unitsInStock", "condition","productImage"); }