Esempio n. 1
0
 /**
  * Binds Json data to this form - that is, handles form submission.
  *
  * @param data data to submit
  * @return a copy of this form filled with the new data
  */
 public Form<T> bind(org.codehaus.jackson.JsonNode data, String... allowedFields) {
   return bind(
       play.libs.Scala.asJava(
           play.api.data.FormUtils.fromJson(
               "", play.api.libs.json.Json.parse(play.libs.Json.stringify(data)))),
       allowedFields);
 }
Esempio n. 2
0
  protected Map<String, String> requestData(Http.Request request) {

    Map<String, String[]> urlFormEncoded = new HashMap<String, String[]>();
    if (request.body().asFormUrlEncoded() != null) {
      urlFormEncoded = request.body().asFormUrlEncoded();
    }

    Map<String, String[]> multipartFormData = new HashMap<String, String[]>();
    if (request.body().asMultipartFormData() != null) {
      multipartFormData = request.body().asMultipartFormData().asFormUrlEncoded();
    }

    Map<String, String> jsonData = new HashMap<String, String>();
    if (request.body().asJson() != null) {
      jsonData =
          play.libs.Scala.asJava(
              play.api.data.FormUtils.fromJson(
                  "",
                  play.api.libs.json.Json.parse(
                      play.libs.Json.stringify(request.body().asJson()))));
    }

    Map<String, String[]> queryString = request.queryString();

    Map<String, String> data = new HashMap<String, String>();

    for (String key : urlFormEncoded.keySet()) {
      String[] values = urlFormEncoded.get(key);
      if (key.endsWith("[]")) {
        String k = key.substring(0, key.length() - 2);
        for (int i = 0; i < values.length; i++) {
          data.put(k + "[" + i + "]", values[i]);
        }
      } else {
        if (values.length > 0) {
          data.put(key, values[0]);
        }
      }
    }

    for (String key : multipartFormData.keySet()) {
      String[] values = multipartFormData.get(key);
      if (key.endsWith("[]")) {
        String k = key.substring(0, key.length() - 2);
        for (int i = 0; i < values.length; i++) {
          data.put(k + "[" + i + "]", values[i]);
        }
      } else {
        if (values.length > 0) {
          data.put(key, values[0]);
        }
      }
    }

    for (String key : jsonData.keySet()) {
      data.put(key, jsonData.get(key));
    }

    for (String key : queryString.keySet()) {
      String[] values = queryString.get(key);
      if (key.endsWith("[]")) {
        String k = key.substring(0, key.length() - 2);
        for (int i = 0; i < values.length; i++) {
          data.put(k + "[" + i + "]", values[i]);
        }
      } else {
        if (values.length > 0) {
          data.put(key, values[0]);
        }
      }
    }

    return data;
  }