Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to bind Double parameter with Play 2.0 routing
    primarykey
    data
    text
    <p>I'm learning myself Play 2.0 (Java API used) and would like to have a double/float parameter (for location coordinates), something like <a href="http://myfooapp.com/events/find?latitude=25.123456&amp;longitude=60.251253" rel="noreferrer">http://myfooapp.com/events/find?latitude=25.123456&amp;longitude=60.251253</a>.</p> <p>I can do this by getting the parameters as String and parsing them at controller etc but can I use automatic binding here?</p> <p>Now, I first tried simply having one double value:</p> <pre><code>GET /events/foo controllers.Application.foo(doublevalue: Double) </code></pre> <p>with</p> <pre><code>public static Result foo(Double doublevalue) { return ok(index.render("Foo:" + doublevalue)); } </code></pre> <p>What I got was <em>"No QueryString binder found for type Double. Try to implement an implicit QueryStringBindable for this type."</em></p> <p>Have I missed something already provided or do I have to make a custom QueryStringBindable that parses Double? </p> <p>I found some instructions on making a custom string query string binder with Scala at <a href="http://julien.richard-foy.fr/blog/2012/04/09/how-to-implement-a-custom-pathbindable-with-play-2/" rel="noreferrer">http://julien.richard-foy.fr/blog/2012/04/09/how-to-implement-a-custom-pathbindable-with-play-2/</a></p> <h2>What I tried:</h2> <p>I implemented DoubleBinder at package binders:</p> <pre><code>import java.util.Map; import play.libs.F.Option; import play.mvc.QueryStringBindable; public class DoubleBinder implements QueryStringBindable&lt;Double&gt;{ @Override public Option&lt;Double&gt; bind(String key, Map&lt;String, String[]&gt; data) { String[] value = data.get(key); if(value == null || value.length == 0) { return Option.None(); } else { return Option.Some(Double.parseDouble(value[0])); } } @Override public String javascriptUnbind() { // TODO Auto-generated method stub return null; } @Override public String unbind(String key) { // TODO Auto-generated method stub return null; } } </code></pre> <p>And tried to add it to project/Build.scala's main:</p> <pre><code>routesImport += "binders._" </code></pre> <p>but same result : "No QueryString binder found for type Double...."</p> <ul> <li>I also changed the routing signature to java.lang.Double but that didn't help either</li> <li>I also changed the DoubleBinder to implement play.api.mvc.QueryStringBindable (instead of play.mvc.QueryStringBindable) both with Double &amp; java.lang.Double at the routing signature but no help still</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload