How implement a Bindable Object

#1

Hi all,

i have a doubt with bindable objects. I explain my case:
I have this class:

public class Cat{
Integer cat_id;
String name;
String color;
}

and i want to send this class, for example to call this method:
addCat/:cat controllers.HomeController.addCat(cat: model.Cat)

but the system show this error:
No URL path binder found for type model.Cat. Try to implement an implicit PathBindable for this type.

I have read the documentation (https://www.playframework.com/documentation/2.6.x/ScalaRequestBinders) but I can’t understand how to implement this part.

Could someone clarify it to me?

Thanks and regards

(Marcos Pereira) #2

Hey @fabian,

The javadocs for PathBindable has an example:

https://www.playframework.com/documentation/2.6.x/api/java/play/mvc/PathBindable.html

For Scala, the missing bit in the docs is how to make your binders available to routes. To do that, you need to add a routesImport in your build.sbt:

import play.PlayImport.PlayKeys._

routesImport += "com.acme.Binders._"

Best.

1 Like