public class CommonWebBindingInitializer implements WebBindingInitializer { @Autowired private Validator validator; @Autowired private ConversionService conversionService; @Override public void initBinder(WebDataBinder binder, WebRequest request) { binder.setValidator(validator); binder.setConversionService(conversionService); } }
@InitBinder public void initBinder(WebDataBinder binder) { binder.initDirectFieldAccess(); binder.setConversionService(new DefaultFormattingConversionService()); }
@Override public void initBinder(WebDataBinder binder) { binder.setAutoGrowNestedPaths(this.autoGrowNestedPaths); if (this.directFieldAccess) { binder.initDirectFieldAccess(); } if (this.messageCodesResolver != null) { binder.setMessageCodesResolver(this.messageCodesResolver); } if (this.bindingErrorProcessor != null) { binder.setBindingErrorProcessor(this.bindingErrorProcessor); } if (this.validator != null && binder.getTarget() != null && this.validator.supports(binder.getTarget().getClass())) { binder.setValidator(this.validator); } if (this.conversionService != null) { binder.setConversionService(this.conversionService); } if (this.propertyEditorRegistrars != null) { for (PropertyEditorRegistrar propertyEditorRegistrar : this.propertyEditorRegistrars) { propertyEditorRegistrar.registerCustomEditors(binder); } } }
@InitBinder public void initBinder(WebDataBinder binder) { binder.initDirectFieldAccess(); binder.setConversionService(new DefaultFormattingConversionService()); LocalValidatorFactoryBean vf = new LocalValidatorFactoryBean(); vf.afterPropertiesSet(); binder.setValidator(vf); }
@Override public void initBinder(WebDataBinder binder) { binder.setAutoGrowNestedPaths(this.autoGrowNestedPaths); if (this.directFieldAccess) { binder.initDirectFieldAccess(); } if (this.messageCodesResolver != null) { binder.setMessageCodesResolver(this.messageCodesResolver); } if (this.bindingErrorProcessor != null) { binder.setBindingErrorProcessor(this.bindingErrorProcessor); } if (this.validator != null && binder.getTarget() != null && this.validator.supports(binder.getTarget().getClass())) { binder.setValidator(this.validator); } if (this.conversionService != null) { binder.setConversionService(this.conversionService); } if (this.propertyEditorRegistrars != null) { for (PropertyEditorRegistrar propertyEditorRegistrar : this.propertyEditorRegistrars) { propertyEditorRegistrar.registerCustomEditors(binder); } } }
@Test public void resolveOptional() throws Exception { WebDataBinder dataBinder = new WebRequestDataBinder(null); dataBinder.setConversionService(new DefaultConversionService()); WebDataBinderFactory factory = mock(WebDataBinderFactory.class); given(factory.createBinder(this.webRequest, null, "foo")).willReturn(dataBinder); MethodParameter param = initMethodParameter(3); Object actual = testResolveArgument(param, factory); assertNotNull(actual); assertEquals(Optional.class, actual.getClass()); assertFalse(((Optional<?>) actual).isPresent()); Foo foo = new Foo(); this.webRequest.setAttribute("foo", foo, getScope()); actual = testResolveArgument(param, factory); assertNotNull(actual); assertEquals(Optional.class, actual.getClass()); assertTrue(((Optional<?>) actual).isPresent()); assertSame(foo, ((Optional<?>) actual).get()); }
@Autowired private ConversionService conversionService; @InitBinder public void initBinder(WebDataBinder binder){ binder.setConversionService(conversionService); }
private WebDataBinder createBinding( final ITest test, final String variableName, final String bindingVariableName, final Object bindingObject, final ConversionService conversionService, final Locale locale, final Map<String,Object> variables) { final WebDataBinder dataBinder = new WebDataBinder(bindingObject, bindingVariableName); dataBinder.setConversionService(conversionService); /* * The following are thymeleaf-testing specific calls in order to allow further customizations of the binders * being created. */ final Map<String,Object> unmodifiableVariables = Collections.unmodifiableMap(variables); // We are iterating it! initBinder(variableName, bindingObject, test, dataBinder, locale, unmodifiableVariables); initBindingResult(variableName, bindingObject, test, dataBinder.getBindingResult(), locale, unmodifiableVariables); return dataBinder; }
private WebDataBinder createBinding( final ITest test, final String variableName, final String bindingVariableName, final Object bindingObject, final ConversionService conversionService, final Locale locale, final Map<String,Object> variables) { final WebDataBinder dataBinder = new WebDataBinder(bindingObject, bindingVariableName); dataBinder.setConversionService(conversionService); /* * The following are thymeleaf-testing specific calls in order to allow further customizations of the binders * being created. */ final Map<String,Object> unmodifiableVariables = Collections.unmodifiableMap(variables); // We are iterating it! initBinder(variableName, bindingObject, test, dataBinder, locale, unmodifiableVariables); initBindingResult(variableName, bindingObject, test, dataBinder.getBindingResult(), locale, unmodifiableVariables); return dataBinder; }
binder.setConversionService(this.conversionService); binder.setAutoGrowNestedPaths(true); binder.setValidator(validator);
@Override public void initBinder(WebDataBinder binder) { binder.setAutoGrowNestedPaths(this.autoGrowNestedPaths); if (this.directFieldAccess) { binder.initDirectFieldAccess(); } if (this.messageCodesResolver != null) { binder.setMessageCodesResolver(this.messageCodesResolver); } if (this.bindingErrorProcessor != null) { binder.setBindingErrorProcessor(this.bindingErrorProcessor); } if (this.validator != null && binder.getTarget() != null && this.validator.supports(binder.getTarget().getClass())) { binder.setValidator(this.validator); } if (this.conversionService != null) { binder.setConversionService(this.conversionService); } if (this.propertyEditorRegistrars != null) { for (PropertyEditorRegistrar propertyEditorRegistrar : this.propertyEditorRegistrars) { propertyEditorRegistrar.registerCustomEditors(binder); } } }
@Override public void initBinder(WebDataBinder binder) { binder.setAutoGrowNestedPaths(this.autoGrowNestedPaths); if (this.directFieldAccess) { binder.initDirectFieldAccess(); } if (this.messageCodesResolver != null) { binder.setMessageCodesResolver(this.messageCodesResolver); } if (this.bindingErrorProcessor != null) { binder.setBindingErrorProcessor(this.bindingErrorProcessor); } if (this.validator != null && binder.getTarget() != null && this.validator.supports(binder.getTarget().getClass())) { binder.setValidator(this.validator); } if (this.conversionService != null) { binder.setConversionService(this.conversionService); } if (this.propertyEditorRegistrars != null) { for (PropertyEditorRegistrar propertyEditorRegistrar : this.propertyEditorRegistrars) { propertyEditorRegistrar.registerCustomEditors(binder); } } }