Reputation: 20182
I am using play framework v2.2 and trying to pass a map to a scala template. The map has a string as its key and a user defined object as its value. My controller is in Java - the template is in Scala.
Controller:
Map<String, UDObject> myMap = new HashMap<String, UDObject>();
UDObject ud1 = new UDObject(a,b,c);
myMap.put("abcd", ud1);
return ok(index.render(myMap));
Index.scala.html Template:
@(myMap: Map[String, UDObject])
When I try reload/eclipse or use play run/start - I get a compilation error complaining that the template could not find the user defined object UDObject. Any idea what I am doing wrong?
Upvotes: 1
Views: 1245
Reputation: 95
It is possible to add this import for all your templates as well.
templatesImport ++= Seq("com.example.UDObject")
Now you don't need to use the fully qualified name of your class.
Upvotes: 1
Reputation: 55569
You need to use the fully qualified name in the declaration of the parameters in the Play template, e.g:
@(myMap: Map[String, com.example.UDObject])
Unfortunately there is no way to import
it, so anything that isn't in the model, view or Scala namespace must use the full name.
Upvotes: 1