Examples of SessionAttributes


Examples of org.springframework.web.bind.annotation.SessionAttributes

          modelAttributeMethods.add(ClassUtils.getMostSpecificMethod(method, handlerType));
        }
      }
    });
    this.typeLevelMapping = handlerType.getAnnotation(RequestMapping.class);
    SessionAttributes sessionAttributes = handlerType.getAnnotation(SessionAttributes.class);
    this.sessionAttributesFound = (sessionAttributes != null);
    if (this.sessionAttributesFound) {
      this.sessionAttributeNames.addAll(Arrays.asList(sessionAttributes.value()));
      this.sessionAttributeTypes.addAll(Arrays.asList(sessionAttributes.types()));
    }
  }
View Full Code Here

Examples of org.springframework.web.bind.annotation.SessionAttributes

   */
  public SessionAttributesHandler(Class<?> handlerType, SessionAttributeStore sessionAttributeStore) {
    Assert.notNull(sessionAttributeStore, "SessionAttributeStore may not be null.");
    this.sessionAttributeStore = sessionAttributeStore;

    SessionAttributes annotation = AnnotationUtils.findAnnotation(handlerType, SessionAttributes.class);
    if (annotation != null) {
      this.attributeNames.addAll(Arrays.asList(annotation.value()));
      this.attributeTypes.addAll(Arrays.<Class<?>>asList(annotation.types()));
    }

    for (String attributeName : this.attributeNames) {
      this.knownAttributeNames.put(attributeName, Boolean.TRUE);
    }
View Full Code Here

Examples of org.springframework.web.bind.annotation.SessionAttributes

          }
        }
      }, ReflectionUtils.USER_DECLARED_METHODS);
    }
    this.typeLevelMapping = AnnotationUtils.findAnnotation(handlerType, RequestMapping.class);
    SessionAttributes sessionAttributes = AnnotationUtils.findAnnotation(handlerType, SessionAttributes.class);
    this.sessionAttributesFound = (sessionAttributes != null);
    if (this.sessionAttributesFound) {
      this.sessionAttributeNames.addAll(Arrays.asList(sessionAttributes.value()));
      this.sessionAttributeTypes.addAll(Arrays.asList(sessionAttributes.types()));
    }
  }
View Full Code Here

Examples of org.springframework.web.bind.annotation.SessionAttributes

          }
        }
      }, ReflectionUtils.USER_DECLARED_METHODS);
    }
    this.typeLevelMapping = AnnotationUtils.findAnnotation(handlerType, RequestMapping.class);
    SessionAttributes sessionAttributes = AnnotationUtils.findAnnotation(handlerType, SessionAttributes.class);
    this.sessionAttributesFound = (sessionAttributes != null);
    if (this.sessionAttributesFound) {
      this.sessionAttributeNames.addAll(Arrays.asList(sessionAttributes.value()));
      this.sessionAttributeTypes.addAll(Arrays.asList(sessionAttributes.types()));
    }
  }
View Full Code Here

Examples of org.springframework.web.bind.annotation.SessionAttributes

   */
  public SessionAttributesHandler(Class<?> handlerType, SessionAttributeStore sessionAttributeStore) {
    Assert.notNull(sessionAttributeStore, "SessionAttributeStore may not be null.");
    this.sessionAttributeStore = sessionAttributeStore;
   
    SessionAttributes annotation = AnnotationUtils.findAnnotation(handlerType, SessionAttributes.class);
    if (annotation != null) {
      this.attributeNames.addAll(Arrays.asList(annotation.value()));
      this.attributeTypes.addAll(Arrays.<Class<?>>asList(annotation.types()));
    }   
  }
View Full Code Here

Examples of org.springframework.web.bind.annotation.SessionAttributes

    return getMethodResolver(handler).hasHandlerMethods();
  }

  public ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
    ExtendedModelMap implicitModel = new ExtendedModelMap();
    SessionAttributes sessionAttributes = handler.getClass().getAnnotation(SessionAttributes.class);
    Set<String> sessionAttrNames = null;

    if (sessionAttributes != null) {
      // Always prevent caching in case of session attribute management.
      checkAndPrepare(request, response, 0, true);
      // Prepare cached set of session attributes names.
      sessionAttrNames = this.sessionAttributeNames.get(handler.getClass());
      if (sessionAttrNames == null) {
        synchronized (this.sessionAttributeNames) {
          sessionAttrNames = this.sessionAttributeNames.get(handler.getClass());
          if (sessionAttrNames == null) {
            sessionAttrNames = Collections.synchronizedSet(new HashSet<String>(4));
            this.sessionAttributeNames.put(handler.getClass(), sessionAttrNames);
          }
        }
      }
    }
    else {
      // Uses configured default cacheSeconds setting.
      checkAndPrepare(request, response, true);
    }

    ServletWebRequest webRequest = new ServletWebRequest(request, response);
    HandlerMethodResolver methodResolver = getMethodResolver(handler);
    Method handlerMethod = methodResolver.resolveHandlerMethod(request);
    ArgumentsResolver argResolver = new ArgumentsResolver(methodResolver.getInitBinderMethods());

    for (Method attributeMethod : methodResolver.getModelAttributeMethods()) {
      Object[] args = argResolver.resolveArguments(
          handler, attributeMethod, request, response, webRequest, implicitModel, sessionAttrNames);
      ReflectionUtils.makeAccessible(attributeMethod);
      Object attrValue = null;
      try {
        attrValue = attributeMethod.invoke(handler, args);
      }
      catch (InvocationTargetException ex) {
        ReflectionUtils.handleInvocationTargetException(ex);
      }
      String attrName = AnnotationUtils.findAnnotation(attributeMethod, ModelAttribute.class).value();
      if ("".equals(attrName)) {
        attrName = Conventions.getVariableNameForReturnType(attributeMethod, attrValue);
      }
      implicitModel.addAttribute(attrName, attrValue);
    }

    Object[] args = argResolver.resolveArguments(
        handler, handlerMethod, request, response, webRequest, implicitModel, sessionAttrNames);
    ReflectionUtils.makeAccessible(handlerMethod);
    Object result = null;
    try {
      result = handlerMethod.invoke(handler, args);
    }
    catch (InvocationTargetException ex) {
      ReflectionUtils.handleInvocationTargetException(ex);
    }
    ModelAndView mav = argResolver.getModelAndView(handlerMethod, result, implicitModel, webRequest);

    if (sessionAttributes != null) {
      if (argResolver.isProcessingComplete()) {
        if (sessionAttrNames != null) {
          for (String attrName : sessionAttrNames) {
            this.sessionAttributeStore.cleanupAttribute(webRequest, attrName);
          }
        }
      }
      // Expose model attributes as session attributes, if required.
      Map<String, Object> model = (mav != null ? mav.getModel() : implicitModel);
      Set<Object> sessionAttributeSet = new HashSet<Object>();
      sessionAttributeSet.addAll(Arrays.asList(sessionAttributes.value()));
      sessionAttributeSet.addAll(Arrays.asList(sessionAttributes.types()));
      for (Map.Entry entry : new HashSet<Map.Entry>(model.entrySet())) {
        String attrName = (String) entry.getKey();
        Object attrValue = entry.getValue();
        if (sessionAttributeSet.contains(attrName) ||
            (attrValue != null && sessionAttributeSet.contains(attrValue.getClass()))) {
View Full Code Here

Examples of org.springframework.web.bind.annotation.SessionAttributes

    public Object[] resolveArguments(
        Object handler, Method handlerMethod, HttpServletRequest request, HttpServletResponse response,
        WebRequest webRequest, ExtendedModelMap implicitModel, Set<String> sessionAttrNames)
        throws Exception {

      SessionAttributes sessionAttributes = handler.getClass().getAnnotation(SessionAttributes.class);
      Set sessionAttributeSet = null;
      if (sessionAttributes != null) {
        sessionAttributeSet = new HashSet();
        sessionAttributeSet.addAll(Arrays.asList(sessionAttributes.value()));
        sessionAttributeSet.addAll(Arrays.asList(sessionAttributes.types()));
      }
      Object[] args = new Object[handlerMethod.getParameterTypes().length];
      String[] paramNames = null;
      boolean paramNamesResolved = false;
      for (int i = 0; i < args.length; i++) {
View Full Code Here

Examples of org.springframework.web.bind.annotation.SessionAttributes

          }
        }
      }, ReflectionUtils.USER_DECLARED_METHODS);
    }
    this.typeLevelMapping = AnnotationUtils.findAnnotation(handlerType, RequestMapping.class);
    SessionAttributes sessionAttributes = AnnotationUtils.findAnnotation(handlerType, SessionAttributes.class);
    this.sessionAttributesFound = (sessionAttributes != null);
    if (this.sessionAttributesFound) {
      this.sessionAttributeNames.addAll(Arrays.asList(sessionAttributes.value()));
      this.sessionAttributeTypes.addAll(Arrays.asList(sessionAttributes.types()));
    }
  }
View Full Code Here

Examples of org.springframework.web.bind.annotation.SessionAttributes

          }
        }
      }, ReflectionUtils.NON_BRIDGED_METHODS);
    }
    this.typeLevelMapping = AnnotationUtils.findAnnotation(handlerType, RequestMapping.class);
    SessionAttributes sessionAttributes = AnnotationUtils.findAnnotation(handlerType, SessionAttributes.class);
    this.sessionAttributesFound = (sessionAttributes != null);
    if (this.sessionAttributesFound) {
      this.sessionAttributeNames.addAll(Arrays.asList(sessionAttributes.value()));
      this.sessionAttributeTypes.addAll(Arrays.asList(sessionAttributes.types()));
    }
  }
View Full Code Here

Examples of org.springframework.web.bind.annotation.SessionAttributes

          modelAttributeMethods.add(ClassUtils.getMostSpecificMethod(method, handlerType));
        }
      }
    });
    this.typeLevelMapping = handlerType.getAnnotation(RequestMapping.class);
    SessionAttributes sessionAttributes = handlerType.getAnnotation(SessionAttributes.class);
    this.sessionAttributesFound = (sessionAttributes != null);
    if (this.sessionAttributesFound) {
      this.sessionAttributeNames.addAll(Arrays.asList(sessionAttributes.value()));
      this.sessionAttributeTypes.addAll(Arrays.asList(sessionAttributes.types()));
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.