I... stuck o.O
I've params in foreign request:
param[62537]=abc;
param[20356]=cde;
param[92837]=fgh;
And I'm looking for any way for binding them ie. with DynamicForm
.
I can get param with:
DynamicForm dynamicForm = form().bindFromRequest();
String firstParam = dynamicForm.field("param[62537]").value();
But of course I dont know the indexes as they are selected within the client-side
form created by the independent app.
When I'm trying to use:
String[] firstParam = dynamicForm.field("param").value(); // it's NULL
String[] firstParam = dynamicForm.get("param"); // it's NULL
or even
String[] params = request().body().asFormUrlEncoded().get("param");
// it's still NULL
Did I miss something really basic, or Play just can't do that?
Not the prettiest way, but did you try to get the keys of the Map returned by asFormUrlEncoded:
Set<String> keys = request().body().asFormUrlEncoded().keySet();
for (String key : keys) {
// check if key begin with "param["
}
The reason why this does not work is that there is no QueryStringBinder for List[String] or Array[String] available yet in the framework. As far as I know, this is planned for Play 2.1.
If you need it now, you can try the solution shown here: QueryStringBinder for List[String]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With