Search code examples
javascalaplayframeworkplayframework-2.0scala-2.10

Play! 2 Rendering JSON data in View from Controller


based on this http://www.markhneedham.com/blog/2012/10/14/play-framework-2-0-rendering-json-data-in-the-view/

myview:

    @(message: String)(myobjects:ObjectNode)
@import com.fasterxml.jackson.databind.JsonNode
@import com.fasterxml.jackson.databind.node.ObjectNode

controller:

ObjectNode myobjects = objectsDAO.getObjects();
return ok(myview.render("test",myobjects ));

error

 not found: type ObjectNode

Doesn't seem to work with ObjectNode, the imports in the view don't seem to be working. Could not find much documentation about passing the view a JSON


Solution

  • Try defining it as such: @(message: String, myobjects:com.fasterxml.jackson.databind.node.ObjectNode), or if that doesn't work, put the @imports in your main.scala.html since it holds the content of your other views....

    <body>
        @content
    </body>