Package org.springframework.web.bind.annotation

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


          paramName = requestParam.value();
          paramRequired = requestParam.required();
          break;
        }
        else if (ModelAttribute.class.isInstance(paramAnn)) {
          ModelAttribute attr = (ModelAttribute) paramAnn;
          attrName = attr.value();
        }
      }
      if (paramName != null && attrName != null) {
        throw new IllegalStateException("@RequestParam and @ModelAttribute are an exclusive choice -" +
            "do not specify both on the same parameter: " + handlerMethod);
View Full Code Here


   * @param returnValue the value returned from a method invocation
   * @param returnType the return type of the method
   * @return the model name, never {@code null} nor empty
   */
  public static String getNameForReturnValue(Object returnValue, MethodParameter returnType) {
    ModelAttribute annot = returnType.getMethodAnnotation(ModelAttribute.class);
    if (annot != null && StringUtils.hasText(annot.value())) {
      return annot.value();
    }
    else {
      Method method = returnType.getMethod();
      Class<?> resolvedType = GenericTypeResolver.resolveReturnType(method, returnType.getDeclaringClass());
      return Conventions.getVariableNameForReturnType(method, resolvedType, returnValue);
View Full Code Here

   *   <li>The parameter type
   * </ol>
   * @return the derived name; never {@code null} or an empty string
   */
  public static String getNameForParameter(MethodParameter parameter) {
    ModelAttribute annot = parameter.getParameterAnnotation(ModelAttribute.class);
    String attrName = (annot != null) ? annot.value() : null;
    return StringUtils.hasText(attrName) ? attrName :  Conventions.getVariableNameForParameter(parameter);
  }
View Full Code Here

          PathVariable pathVar = (PathVariable) paramAnn;
          pathVarName = pathVar.value();
          annotationsFound++;
        }
        else if (ModelAttribute.class.isInstance(paramAnn)) {
          ModelAttribute attr = (ModelAttribute) paramAnn;
          attrName = attr.value();
          annotationsFound++;
        }
        else if (Value.class.isInstance(paramAnn)) {
          defaultValue = ((Value) paramAnn).value();
        }
View Full Code Here

  }

  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);
    }
    implicitModel.addAttribute(attrName, returnValue);
View Full Code Here

              paramName = requestParam.value();
              paramRequired = requestParam.required();
              break;
            }
            else if (ModelAttribute.class.isInstance(paramAnn)) {
              ModelAttribute attr = (ModelAttribute) paramAnn;
              if (!"".equals(attr.value())) {
                attrName = attr.value();
              }
            }
          }
          if (attrName == null) {
            attrName = Conventions.getVariableNameForParameter(param);
View Full Code Here

        // Either returned null or was 'void' return.
        return null;
      }
      else if (!BeanUtils.isSimpleProperty(returnValue.getClass())) {
        // Assume a single model attribute...
        ModelAttribute attr = AnnotationUtils.findAnnotation(handlerMethod, ModelAttribute.class);
        String attrName = (attr != null ? attr.value() : "");
        ModelAndView mav = new ModelAndView().addAllObjects(implicitModel);
        if ("".equals(attrName)) {
          Class resolvedType = GenericTypeResolver.resolveReturnType(handlerMethod, handlerType);
          attrName = Conventions.getVariableNameForReturnType(handlerMethod, resolvedType, returnValue);
        }
View Full Code Here

          return new ModelAndView().addAllObjects(implicitModel);
        }
      }
      else if (!BeanUtils.isSimpleProperty(returnValue.getClass())) {
        // Assume a single model attribute...
        ModelAttribute attr = AnnotationUtils.findAnnotation(handlerMethod, ModelAttribute.class);
        String attrName = (attr != null ? attr.value() : "");
        ModelAndView mav = new ModelAndView().addAllObjects(implicitModel);
        if ("".equals(attrName)) {
          Class resolvedType = GenericTypeResolver.resolveReturnType(handlerMethod, handlerType);
          attrName = Conventions.getVariableNameForReturnType(handlerMethod, resolvedType, returnValue);
        }
View Full Code Here

    }

    static String extractModelAttributeName(JoinPoint jp) {
        Signature sig = jp.getSignature();
        Method method = (sig instanceof MethodSignature) ? ((MethodSignature) sig).getMethod() : null;
        ModelAttribute ma = (method == null) ? null : method.getAnnotation(ModelAttribute.class);
        String modelAttrName = (ma == null) ? null : ma.value();
        if (!StringUtil.isEmpty(modelAttrName)) {
            return modelAttrName;
        }

        if (method == null) {
View Full Code Here

   *   <li>The parameter type
   * </ol>
   * @return the derived name; never {@code null} or an empty string
   */
  public static String getNameForParameter(MethodParameter parameter) {
    ModelAttribute annot = parameter.getParameterAnnotation(ModelAttribute.class);
    String attrName = (annot != null) ? annot.value() : null;
    return StringUtils.hasText(attrName) ? attrName :  Conventions.getVariableNameForParameter(parameter);
  }
View Full Code Here

TOP

Related Classes of org.springframework.web.bind.annotation.ModelAttribute

Copyright © 2018 www.massapicom. 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.