Edit: Sorry, I think I did not translate this in good faith, and it is uglier. myobj.itemcan also be null, so you have to wrap it in Option(_):
@Option(myobj).flatMap(i => Option(i.item)).flatMap(s => Option(s.subitem)).getOrElse("empty")
or
@((for {o <- Option(myobj)
item <- Option(o.item)
subitem <- Option(item.subitem)
}).getOrElse("empty"))
Please note that if for such a normal case in the playframework there is additional sugar.
source
share