I would like to know if there is some kind of instanceof
functionality in the template engine of the Play (2.0) framework. This would allow me to effectively use the inheritance structure in my model layer.
This is basically what I would like (except that this template doesn't compile):
@(instance: Superclass)
@main {
@if(instance instanceof Subclass) {
Subclass instanceOfSubclass = (Subclass) instance;
}
}
Edit: I mean in specific Play for Java.
Use Scala pattern matching.
@(instance: Superclass)
@main {
@instance match {
case foo: Foo => {
<a href="@routes.Foo.index()">@foo.title</a>
}
case bar: Bar => {
<a href="@routes.Bar.index()">@bar.title</a>
}
}
}