/** * Template method to create a new InitBinderDataBinderFactory instance. * <p>The default implementation creates a ServletRequestDataBinderFactory. * This can be overridden for custom ServletRequestDataBinder subclasses. * @param binderMethods {@code @InitBinder} methods * @return the InitBinderDataBinderFactory instance to use * @throws Exception in case of invalid state or arguments */ protected InitBinderDataBinderFactory createDataBinderFactory(List<InvocableHandlerMethod> binderMethods) throws Exception { return new ServletRequestDataBinderFactory(binderMethods, getWebBindingInitializer()); }
/** * Look current Thread for {@link ServletRequestDataBinder} created by * {@link DataBinderMappingJackson2HttpMessageConverter}, if found return * it, otherwise it delegates on parent method. * * @param target * @param objectName * @param request * @return ServletRequestDataBinder */ @Override protected ServletRequestDataBinder createBinderInstance(Object target, String objectName, NativeWebRequest request) { try { ServletRequestDataBinder binder = (ServletRequestDataBinder) ThreadLocalUtil .getThreadVariable(BindingResult.MODEL_KEY_PREFIX .concat("JSON_DataBinder")); if (binder != null) { return binder; } return super.createBinderInstance(target, objectName, request); } finally { ThreadLocalUtil.destroy(); } }
/** * Template method to create a new InitBinderDataBinderFactory instance. * <p>The default implementation creates a ServletRequestDataBinderFactory. * This can be overridden for custom ServletRequestDataBinder subclasses. * @param binderMethods {@code @InitBinder} methods * @return the InitBinderDataBinderFactory instance to use * @throws Exception in case of invalid state or arguments */ protected InitBinderDataBinderFactory createDataBinderFactory(List<InvocableHandlerMethod> binderMethods) throws Exception { return new ServletRequestDataBinderFactory(binderMethods, getWebBindingInitializer()); }
@Before public void setup() throws Exception { processor = new ServletModelAttributeMethodProcessor(false); ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer(); initializer.setConversionService(new DefaultConversionService()); binderFactory = new ServletRequestDataBinderFactory(null, initializer); mavContainer = new ModelAndViewContainer(); request = new MockHttpServletRequest(); webRequest = new ServletWebRequest(request); Method method = getClass().getDeclaredMethod("modelAttribute", TestBean.class, TestBeanWithoutStringConstructor.class, Optional.class); testBeanModelAttr = new MethodParameter(method, 0); testBeanWithoutStringConstructorModelAttr = new MethodParameter(method, 1); testBeanWithOptionalModelAttr = new MethodParameter(method, 2); }
/** * Template method to create a new InitBinderDataBinderFactory instance. * <p>The default implementation creates a ServletRequestDataBinderFactory. * This can be overridden for custom ServletRequestDataBinder subclasses. * @param binderMethods {@code @InitBinder} methods * @return the InitBinderDataBinderFactory instance to use * @throws Exception in case of invalid state or arguments */ protected InitBinderDataBinderFactory createDataBinderFactory(List<InvocableHandlerMethod> binderMethods) throws Exception { return new ServletRequestDataBinderFactory(binderMethods, getWebBindingInitializer()); }
/** * Template method to create a new InitBinderDataBinderFactory instance. * <p>The default implementation creates a ServletRequestDataBinderFactory. * This can be overridden for custom ServletRequestDataBinder subclasses. * * @param binderMethods {@code @InitBinder} methods * @return the InitBinderDataBinderFactory instance to use * @throws Exception in case of invalid state or arguments */ protected InitBinderDataBinderFactory createDataBinderFactory( List<InvocableHandlerMethod> binderMethods) throws Exception { return new ServletRequestDataBinderFactory(binderMethods, getWebBindingInitializer()); }
private WebDataBinderFactory createDataBinderFactory(Object bean, Class<?> handlerType) { List<InvocableHandlerMethod> initBinderMethods = new ArrayList<InvocableHandlerMethod>(); Set<Method> binderMethods = this.initBinderMethodCache.get(handlerType); if (binderMethods == null) { binderMethods = HandlerMethodSelector.selectMethods(handlerType, RequestMappingHandlerAdapter.INIT_BINDER_METHODS); this.initBinderMethodCache.put(handlerType, binderMethods); } for (Method method : binderMethods) { InvocableHandlerMethod binderMethod = createInvocableBinderMethod(bean, method); binderMethod.setHandlerMethodArgumentResolvers(this.initBinderArgumentResolvers); binderMethod.setDataBinderFactory(new DefaultDataBinderFactory(this.webBindingInitializer)); binderMethod.setParameterNameDiscoverer(this.parameterNameDiscoverer); initBinderMethods.add(binderMethod); } return new ServletRequestDataBinderFactory(initBinderMethods, this.webBindingInitializer); }