I\'m learning myself Play 2.0 (Java API used) and would like to have a double/float parameter (for location coordinates), something like http://myfooapp.com/events/find?lati
Currently (in Play 2.0), Java binders only work with self-recursive types. That is, types looking like the following:
class Foo extends QueryStringBindable {
…
}
So, if you want to define a binder for java.lang.Double, which is an existing type of Java, you need to wrap it in a self-recursive type. For example:
package util;
public class DoubleW implements QueryStringBindable {
public Double value = null;
@Override
public Option bind(String key, Map data) {
String[] vs = data.get(key);
if (vs != null && vs.length > 0) {
String v = vs[0];
value = Double.parseDouble(v);
return F.Some(this);
}
return F.None();
}
@Override
public String unbind(String key) {
return key + "=" + value;
}
@Override
public String javascriptUnbind() {
return value.toString();
}
}
Then you can use it as follows in your application:
GET /foo controllers.Application.action(d: util.DoubleW)
public static Result action(DoubleW d) {
…
}