List of usage examples for org.springframework.ui ExtendedModelMap addAttribute
@Override
public ExtendedModelMap addAttribute(String attributeName, @Nullable Object attributeValue)
From source file:org.terasoluna.gfw.functionaltest.app.exceptionhandling.ExceptionHandlingController.java
@ExceptionHandler(ContinueException.class) @ResponseStatus(HttpStatus.CONTINUE)//from w ww . j a v a 2s .c o m public ModelAndView handleException(ContinueException e) { ExtendedModelMap modelMap = new ExtendedModelMap(); modelMap.addAttribute("exceptionMessage", e.getMessage()); return new ModelAndView("exceptionhandling/exceptionHandler", modelMap); }
From source file:org.terasoluna.gfw.functionaltest.app.exceptionhandling.ExceptionHandlingController.java
@ExceptionHandler(NormalException.class) @ResponseStatus(HttpStatus.OK)// w w w . java 2 s . c o m public ModelAndView handleException(NormalException e) { ExtendedModelMap modelMap = new ExtendedModelMap(); modelMap.addAttribute("exceptionMessage", e.getMessage()); return new ModelAndView("exceptionhandling/exceptionHandler", modelMap); }
From source file:org.terasoluna.gfw.functionaltest.app.exceptionhandling.ExceptionHandlingController.java
@ExceptionHandler(MultipleChoicesException.class) @ResponseStatus(HttpStatus.MULTIPLE_CHOICES) public ModelAndView handleException(MultipleChoicesException e) { ExtendedModelMap modelMap = new ExtendedModelMap(); modelMap.addAttribute("exceptionMessage", e.getMessage()); return new ModelAndView("exceptionhandling/exceptionHandler", modelMap); }
From source file:org.terasoluna.gfw.functionaltest.app.exceptionhandling.ExceptionHandlingController.java
@ExceptionHandler(OptimisticLockingFailureException.class) @ResponseStatus(HttpStatus.CONFLICT)/*from w w w . jav a 2s .co m*/ public ModelAndView handleException(OptimisticLockingFailureException e) { ExtendedModelMap modelMap = new ExtendedModelMap(); modelMap.addAttribute("exceptionMessage", e.getMessage()); return new ModelAndView("exceptionhandling/exceptionHandler", modelMap); }
From source file:org.terasoluna.gfw.functionaltest.app.exceptionhandling.ExceptionHandlingController.java
@ExceptionHandler(PessimisticLockingFailureException.class) @ResponseStatus(HttpStatus.CONFLICT)/*from w w w . j av a2s. c om*/ public ModelAndView handleException(PessimisticLockingFailureException e) { ExtendedModelMap modelMap = new ExtendedModelMap(); modelMap.addAttribute("exceptionMessage", e.getMessage()); return new ModelAndView("exceptionhandling/exceptionHandler", modelMap); }
From source file:com.revolsys.ui.web.rest.interceptor.WebAnnotationMethodHandlerAdapter.java
protected final void addReturnValueAsModelAttribute(final Method handlerMethod, final Class<?> handlerType, final Object returnValue, final ExtendedModelMap implicitModel) { final ModelAttribute attr = AnnotationUtils.findAnnotation(handlerMethod, ModelAttribute.class); String attrName = attr != null ? attr.value() : ""; if ("".equals(attrName)) { final Class<?> resolvedType = GenericTypeResolver.resolveReturnType(handlerMethod, handlerType); attrName = Conventions.getVariableNameForReturnType(handlerMethod, resolvedType, returnValue); }/*from w ww . j a v a2s. c o m*/ implicitModel.addAttribute(attrName, returnValue); }
From source file:org.ambraproject.wombat.controller.AppRootPage.java
private ModelAndView serveCustomRootPage(String rootPagePath) { ExtendedModelMap model = new ExtendedModelMap(); model.addAttribute("rootPage", new File(rootPagePath)); return new ModelAndView(HtmlFileView.INSTANCE, model); }
From source file:org.springframework.data.document.web.bind.annotation.support.HandlerMethodInvoker.java
public final Object invokeHandlerMethod(Method handlerMethod, Object handler, NativeWebRequest webRequest, ExtendedModelMap implicitModel) throws Exception { Method handlerMethodToInvoke = BridgeMethodResolver.findBridgedMethod(handlerMethod); try {/* w w w. jav a2 s . c o m*/ boolean debug = logger.isDebugEnabled(); for (String attrName : this.methodResolver.getActualSessionAttributeNames()) { Object attrValue = this.sessionAttributeStore.retrieveAttribute(webRequest, attrName); if (attrValue != null) { implicitModel.addAttribute(attrName, attrValue); } } for (Method attributeMethod : this.methodResolver.getModelAttributeMethods()) { Method attributeMethodToInvoke = BridgeMethodResolver.findBridgedMethod(attributeMethod); Object[] args = resolveHandlerArguments(attributeMethodToInvoke, handler, webRequest, implicitModel); if (debug) { logger.debug("Invoking model attribute method: " + attributeMethodToInvoke); } String attrName = AnnotationUtils.findAnnotation(attributeMethod, ModelAttribute.class).value(); if (!"".equals(attrName) && implicitModel.containsAttribute(attrName)) { continue; } ReflectionUtils.makeAccessible(attributeMethodToInvoke); Object attrValue = attributeMethodToInvoke.invoke(handler, args); if ("".equals(attrName)) { Class resolvedType = GenericTypeResolver.resolveReturnType(attributeMethodToInvoke, handler.getClass()); attrName = Conventions.getVariableNameForReturnType(attributeMethodToInvoke, resolvedType, attrValue); } if (!implicitModel.containsAttribute(attrName)) { implicitModel.addAttribute(attrName, attrValue); } } Object[] args = resolveHandlerArguments(handlerMethodToInvoke, handler, webRequest, implicitModel); if (debug) { logger.debug("Invoking request handler method: " + handlerMethodToInvoke); } ReflectionUtils.makeAccessible(handlerMethodToInvoke); return handlerMethodToInvoke.invoke(handler, args); } catch (IllegalStateException ex) { // Internal assertion failed (e.g. invalid signature): // throw exception with full handler method context... throw new HandlerMethodInvocationException(handlerMethodToInvoke, ex); } catch (InvocationTargetException ex) { // User-defined @ModelAttribute/@InitBinder/@RequestMapping method threw an exception... ReflectionUtils.rethrowException(ex.getTargetException()); return null; } }
From source file:org.springframework.data.document.web.bind.annotation.support.HandlerMethodInvoker.java
protected final void addReturnValueAsModelAttribute(Method handlerMethod, Class handlerType, Object returnValue, ExtendedModelMap implicitModel) { ModelAttribute attr = AnnotationUtils.findAnnotation(handlerMethod, ModelAttribute.class); String attrName = (attr != null ? attr.value() : ""); if ("".equals(attrName)) { Class resolvedType = GenericTypeResolver.resolveReturnType(handlerMethod, handlerType); attrName = Conventions.getVariableNameForReturnType(handlerMethod, resolvedType, returnValue); }/* w w w . j a v a2 s . c o m*/ implicitModel.addAttribute(attrName, returnValue); }
From source file:org.springframework.web.bind.annotation.support.HandlerMethodInvoker.java
public final Object invokeHandlerMethod(Method handlerMethod, Object handler, NativeWebRequest webRequest, ExtendedModelMap implicitModel) throws Exception { Method handlerMethodToInvoke = BridgeMethodResolver.findBridgedMethod(handlerMethod); try {/*from w w w . jav a2 s .c om*/ boolean debug = logger.isDebugEnabled(); for (String attrName : this.methodResolver.getActualSessionAttributeNames()) { Object attrValue = this.sessionAttributeStore.retrieveAttribute(webRequest, attrName); if (attrValue != null) { implicitModel.addAttribute(attrName, attrValue); } } for (Method attributeMethod : this.methodResolver.getModelAttributeMethods()) { Method attributeMethodToInvoke = BridgeMethodResolver.findBridgedMethod(attributeMethod); Object[] args = resolveHandlerArguments(attributeMethodToInvoke, handler, webRequest, implicitModel); if (debug) { logger.debug("Invoking model attribute method: " + attributeMethodToInvoke); } String attrName = AnnotationUtils.findAnnotation(attributeMethod, ModelAttribute.class).value(); if (!"".equals(attrName) && implicitModel.containsAttribute(attrName)) { continue; } ReflectionUtils.makeAccessible(attributeMethodToInvoke); Object attrValue = attributeMethodToInvoke.invoke(handler, args); if ("".equals(attrName)) { Class<?> resolvedType = GenericTypeResolver.resolveReturnType(attributeMethodToInvoke, handler.getClass()); attrName = Conventions.getVariableNameForReturnType(attributeMethodToInvoke, resolvedType, attrValue); } if (!implicitModel.containsAttribute(attrName)) { implicitModel.addAttribute(attrName, attrValue); } } Object[] args = resolveHandlerArguments(handlerMethodToInvoke, handler, webRequest, implicitModel); if (debug) { logger.debug("Invoking request handler method: " + handlerMethodToInvoke); } ReflectionUtils.makeAccessible(handlerMethodToInvoke); return handlerMethodToInvoke.invoke(handler, args); } catch (IllegalStateException ex) { // Internal assertion failed (e.g. invalid signature): // throw exception with full handler method context... throw new HandlerMethodInvocationException(handlerMethodToInvoke, ex); } catch (InvocationTargetException ex) { // User-defined @ModelAttribute/@InitBinder/@RequestMapping method threw an exception... ReflectionUtils.rethrowException(ex.getTargetException()); return null; } }