Search in sources :

Example 1 with ModelMethodProcessor

use of cn.taketoday.web.bind.resolver.ModelMethodProcessor in project today-framework by TAKETODAY.

the class ModelFactoryTests method createModelFactory.

private ModelFactory createModelFactory(String methodName, Class<?>... parameterTypes) throws Throwable {
    InvocableHandlerMethod modelMethod = createHandlerMethod(methodName, parameterTypes);
    ParameterResolvingRegistry registry = new ParameterResolvingRegistry();
    registry.getCustomizedStrategies().add(new ModelMethodProcessor());
    modelMethod.setResolvingRegistry(registry);
    return new ModelFactory(Collections.singletonList(modelMethod), null, this.attributeHandler);
}
Also used : ModelMethodProcessor(cn.taketoday.web.bind.resolver.ModelMethodProcessor) ParameterResolvingRegistry(cn.taketoday.web.bind.resolver.ParameterResolvingRegistry)

Example 2 with ModelMethodProcessor

use of cn.taketoday.web.bind.resolver.ModelMethodProcessor in project today-framework by TAKETODAY.

the class ModelFactoryOrderingTests method runTest.

private void runTest(Object controller) throws Throwable {
    ParameterResolvingRegistry resolvers = new ParameterResolvingRegistry();
    resolvers.addStrategies(new ModelAttributeMethodProcessor(false));
    resolvers.addStrategies(new ModelMethodProcessor());
    BindingContext dataBinderFactory = new BindingContext(null);
    Class<?> type = controller.getClass();
    Set<Method> methods = MethodIntrospector.filterMethods(type, METHOD_FILTER);
    List<InvocableHandlerMethod> modelMethods = new ArrayList<>();
    for (Method method : methods) {
        InvocableHandlerMethod modelMethod = new InvocableHandlerMethod(controller, method);
        modelMethod.setResolvingRegistry(resolvers);
        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()) {
        logger.debug(String.join(" >> ", getInvokedMethods()));
    }
}
Also used : ModelMethodProcessor(cn.taketoday.web.bind.resolver.ModelMethodProcessor) ArrayList(java.util.ArrayList) ParameterResolvingRegistry(cn.taketoday.web.bind.resolver.ParameterResolvingRegistry) Method(java.lang.reflect.Method) BindingContext(cn.taketoday.web.BindingContext)

Aggregations

ModelMethodProcessor (cn.taketoday.web.bind.resolver.ModelMethodProcessor)2 ParameterResolvingRegistry (cn.taketoday.web.bind.resolver.ParameterResolvingRegistry)2 BindingContext (cn.taketoday.web.BindingContext)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1