Reputation: 1160
I am only able to access a form value in my Play Framework 2 template like this:
@eventForm("options[0].safeToDelete").value.toString()
But I need to also be able to access it from within a method in the template, like this:
optionFields(option: Field)(implicit handler: FieldConstructor, lang: play.api.i18n.Lang) = {
@option("safeToDelete").value.toString()
}
@optionFields(eventForm("options[0]"))
The first example returns true
.
The second one returns Some(true)
.
How can I get the second one to return true
?
Upvotes: 2
Views: 2192
Reputation: 9548
In Scala Option[T]
is a different way of handling null objects.
It has two subtypes - Some[T]
and None
. One of the many ways you can handle this is as below,
@option("safeToDelete").value.getOrElse(false).toString
Read through for more.. http://www.tutorialspoint.com/scala/scala_options.htm
Upvotes: 3