Skip to content
Browse files

bindFormRequest(Map<String,String[]>) in the Java API

  • Loading branch information...
1 parent 18cbd4f commit 6f64dd845d02659c9a8782121c34cec242a80c56 @guillaumebort guillaumebort committed Jun 8, 2012
Showing with 23 additions and 0 deletions.
  1. +23 −0 framework/src/play/src/main/java/play/data/Form.java
View
23 framework/src/play/src/main/java/play/data/Form.java
@@ -187,6 +187,29 @@ public Form(String rootName, Class<T> clazz, Map<String,String> data, Map<String
}
/**
+ * Binds request data to this form - that is, handles form submission.
+ *
+ * @return a copy of this form filled with the new data
+ */
+ public Form<T> bindFromRequest(Map<String,String[]> requestData, String... allowedFields) {
+ Map<String,String> data = new HashMap<String,String>();
+ for(String key: requestData.keySet()) {
+ String[] values = requestData.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 bind(data, allowedFields);
+ }
+
+ /**
* Binds Json data to this form - that is, handles form submission.
*
* @param data data to submit

0 comments on commit 6f64dd8

Please sign in to comment.
Something went wrong with that request. Please try again.