コード例 #1
0
 protected void copyParamsFromPreviousRequest(
     GrailsWebRequest previousRequestAttributes, GrailsWebRequest requestAttributes) {
   Map previousParams = previousRequestAttributes.getParams();
   Map params = requestAttributes.getParams();
   for (Iterator i = previousParams.keySet().iterator(); i.hasNext(); ) {
     String name = (String) i.next();
     params.put(name, previousParams.get(name));
   }
 }
コード例 #2
0
  protected Object findArg(HttpServletRequest request, Class<?> type, String name) {

    if (String.class.equals(type)) {
      return request.getParameter(name);
    }

    if (PRIMITIVE_CLASSES.contains(type) || TYPE_TO_CONVERSION_METHOD_NAME.containsKey(type)) {

      String conversionMethodName;
      if (TYPE_TO_CONVERSION_METHOD_NAME.containsKey(type)) {
        conversionMethodName = TYPE_TO_CONVERSION_METHOD_NAME.get(type);
      } else {
        conversionMethodName = type.getName();
      }

      GrailsWebRequest grailsRequest =
          (GrailsWebRequest) RequestContextHolder.getRequestAttributes();
      GrailsParameterMap params = grailsRequest.getParams();

      return getParamValue(params, conversionMethodName, name);
    }

    log.warn("Unsupported parameter type " + type + " for parameter " + name);
    return null;
  }
コード例 #3
0
  @SuppressWarnings({"unchecked", "rawtypes"})
  protected void copyParamsFromPreviousRequest(
      RequestAttributes previousRequestAttributes, GrailsWebRequest requestAttributes) {
    if (!(previousRequestAttributes instanceof GrailsWebRequest)) {
      return;
    }

    Map previousParams = ((GrailsWebRequest) previousRequestAttributes).getParams();
    Map params = requestAttributes.getParams();
    for (Object o : previousParams.keySet()) {
      String name = (String) o;
      params.put(name, previousParams.get(name));
    }
  }
コード例 #4
0
  /**
   * Populates request parameters for the given UrlMappingInfo instance using the GrailsWebRequest
   *
   * @param webRequest The Map instance
   * @see org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequest
   */
  @SuppressWarnings("unchecked")
  protected void populateParamsForMapping(GrailsWebRequest webRequest) {
    Map dispatchParams = webRequest.getParams();
    String encoding = webRequest.getRequest().getCharacterEncoding();
    if (encoding == null) encoding = "UTF-8";

    for (Map.Entry<String, Object> entry : params.entrySet()) {
      String name = entry.getKey();
      Object param = entry.getValue();
      if (param instanceof Closure) {
        param = evaluateNameForValue(param);
      }
      if (param instanceof String) {
        try {
          param = URLDecoder.decode((String) param, encoding);
        } catch (UnsupportedEncodingException e) {
          param = evaluateNameForValue(param);
        }
      }
      dispatchParams.put(name, param);
    }

    final String viewName = getViewName();
    if (viewName == null && getURI() == null) {
      webRequest.setControllerName(getControllerName());
      webRequest.setActionName(getActionName());
    }

    String id = getId();
    if (!StringUtils.isBlank(id))
      try {
        dispatchParams.put(GrailsWebRequest.ID_PARAMETER, URLDecoder.decode(id, encoding));
      } catch (UnsupportedEncodingException e) {
        dispatchParams.put(GrailsWebRequest.ID_PARAMETER, id);
      }
  }