Java Play! Ebean/JPA notation not displaying in Scala template

As an aspiring Java/Web Developer, I have recently started playing around with the new Java Web Framework, Play!. So far it has been very nice. It is modeled after the Rails platform and offers some nice feature and seems to have garnered a significant amount of support from the Java community. One problem that has consistently plagued me is lack of documentation. Mostly on the JPA/Ebeam ORM setup used in Play!.

Certain JPA anotations are not directly accessable from within the Scala templates. The @Lob is the one that really bit me for a while.

The following would not work.

public String content;

and then in my template:

@(post: Post)
<p> @post.content </p>

From reading this post on Play!’s google groups, it appears that you must use private field and public accessor methods if you want to use Ebean lazy loading (or any other Java magic) from Scala code. This is not a problem and most of time, you should have private variables and getter/setters, but it simply the fact that this was not documented that really wasted my time.

So I added a simple getter for my post model:

public String getContent() {
    	return content;

and then in my template:

<p> @post.getContent() </p>

Leave a Reply

Your email address will not be published. Required fields are marked *