use of org.springframework.web.method.support.InvocableHandlerMethod in project spring-framework by spring-projects.
the class ModelFactory method invokeModelAttributeMethods.
/**
* Invoke model attribute methods to populate the model.
* Attributes are added only if not already present in the model.
*/
private void invokeModelAttributeMethods(NativeWebRequest request, ModelAndViewContainer container) throws Exception {
while (!this.modelMethods.isEmpty()) {
InvocableHandlerMethod modelMethod = getNextModelMethod(container).getHandlerMethod();
ModelAttribute ann = modelMethod.getMethodAnnotation(ModelAttribute.class);
Assert.state(ann != null, "No ModelAttribute annotation");
if (container.containsAttribute(ann.name())) {
if (!ann.binding()) {
container.setBindingDisabled(ann.name());
}
continue;
}
Object returnValue = modelMethod.invokeForRequest(request, container);
if (modelMethod.isVoid()) {
if (StringUtils.hasText(ann.value())) {
if (logger.isDebugEnabled()) {
logger.debug("Name in @ModelAttribute is ignored because method returns void: " + modelMethod.getShortLogMessage());
}
}
continue;
}
String returnValueName = getNameForReturnValue(returnValue, modelMethod.getReturnType());
if (!ann.binding()) {
container.setBindingDisabled(returnValueName);
}
if (!container.containsAttribute(returnValueName)) {
container.addAttribute(returnValueName, returnValue);
}
}
}
use of org.springframework.web.method.support.InvocableHandlerMethod in project spring-framework by spring-projects.
the class MvcNamespaceTests method setup.
@BeforeEach
public void setup() throws Exception {
TestMockServletContext servletContext = new TestMockServletContext();
appContext = new XmlWebApplicationContext();
appContext.setServletContext(servletContext);
LocaleContextHolder.setLocale(Locale.US);
String attributeName = WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE;
appContext.getServletContext().setAttribute(attributeName, appContext);
handler = new TestController();
handlerMethod = new InvocableHandlerMethod(handler, TestController.class.getMethod("testBind", Date.class, Double.class, TestBean.class, BindingResult.class));
}
Aggregations