use of org.springframework.web.bind.support.WebDataBinderFactory in project spring-framework by spring-projects.
the class ModelFactoryOrderingTests method runTest.
private void runTest(Object controller) throws Exception {
HandlerMethodArgumentResolverComposite resolvers = new HandlerMethodArgumentResolverComposite();
resolvers.addResolver(new ModelAttributeMethodProcessor(false));
resolvers.addResolver(new ModelMethodProcessor());
WebDataBinderFactory dataBinderFactory = new DefaultDataBinderFactory(null);
Class<?> type = controller.getClass();
Set<Method> methods = MethodIntrospector.selectMethods(type, METHOD_FILTER);
List<InvocableHandlerMethod> modelMethods = new ArrayList<>();
for (Method method : methods) {
InvocableHandlerMethod modelMethod = new InvocableHandlerMethod(controller, method);
modelMethod.setHandlerMethodArgumentResolvers(resolvers);
modelMethod.setDataBinderFactory(dataBinderFactory);
modelMethods.add(modelMethod);
}
Collections.shuffle(modelMethods);
SessionAttributesHandler sessionHandler = new SessionAttributesHandler(type, this.sessionAttributeStore);
ModelFactory factory = new ModelFactory(modelMethods, dataBinderFactory, sessionHandler);
factory.initModel(this.webRequest, this.mavContainer, new HandlerMethod(controller, "handle"));
if (logger.isDebugEnabled()) {
StringBuilder sb = new StringBuilder();
for (String name : getInvokedMethods()) {
sb.append(" >> ").append(name);
}
logger.debug(sb);
}
}
use of org.springframework.web.bind.support.WebDataBinderFactory in project spring-framework by spring-projects.
the class ModelFactoryTests method updateModelBindingResult.
@Test
public void updateModelBindingResult() throws Exception {
String commandName = "attr1";
Object command = new Object();
ModelAndViewContainer container = new ModelAndViewContainer();
container.addAttribute(commandName, command);
WebDataBinder dataBinder = new WebDataBinder(command, commandName);
WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class);
given(binderFactory.createBinder(this.webRequest, command, commandName)).willReturn(dataBinder);
ModelFactory modelFactory = new ModelFactory(null, binderFactory, this.attributeHandler);
modelFactory.updateModel(this.webRequest, container);
assertEquals(command, container.getModel().get(commandName));
String bindingResultKey = BindingResult.MODEL_KEY_PREFIX + commandName;
assertSame(dataBinder.getBindingResult(), container.getModel().get(bindingResultKey));
assertEquals(2, container.getModel().size());
}
use of org.springframework.web.bind.support.WebDataBinderFactory in project spring-framework by spring-projects.
the class InitBinderDataBinderFactoryTests method createBinder.
@Test
public void createBinder() throws Exception {
WebDataBinderFactory factory = createFactory("initBinder", WebDataBinder.class);
WebDataBinder dataBinder = factory.createBinder(this.webRequest, null, null);
assertNotNull(dataBinder.getDisallowedFields());
assertEquals("id", dataBinder.getDisallowedFields()[0]);
}
use of org.springframework.web.bind.support.WebDataBinderFactory in project spring-framework by spring-projects.
the class InitBinderDataBinderFactoryTests method createBinderTypeConversion.
@Test
public void createBinderTypeConversion() throws Exception {
this.webRequest.getNativeRequest(MockHttpServletRequest.class).setParameter("requestParam", "22");
this.argumentResolvers.addResolver(new RequestParamMethodArgumentResolver(null, false));
WebDataBinderFactory factory = createFactory("initBinderTypeConversion", WebDataBinder.class, int.class);
WebDataBinder dataBinder = factory.createBinder(this.webRequest, null, "foo");
assertNotNull(dataBinder.getDisallowedFields());
assertEquals("requestParam-22", dataBinder.getDisallowedFields()[0]);
}
use of org.springframework.web.bind.support.WebDataBinderFactory in project spring-framework by spring-projects.
the class InitBinderDataBinderFactoryTests method createBinderWithAttrName.
@Test
public void createBinderWithAttrName() throws Exception {
WebDataBinderFactory factory = createFactory("initBinderWithAttributeName", WebDataBinder.class);
WebDataBinder dataBinder = factory.createBinder(this.webRequest, null, "foo");
assertNotNull(dataBinder.getDisallowedFields());
assertEquals("id", dataBinder.getDisallowedFields()[0]);
}
Aggregations