I have a Play 2.0 template with the following first lines:
@(item: Option[Item] = None,
violations: java.util.Set[ConstraintViolation[Item]] = new util.HashSet[ConstraintViolation[Item]]())
@import java.util
@import javax.validation.ConstraintViolation
But the ConstraintViolation
cannot be found and I get the error:
not found: type ConstraintViolation
The bean validation API itself is available in the application since I can use it in a controller. What can I do to import it in my template?
A type safe template engine based on Scala Play comes with Twirl, a powerful Scala-based template engine, whose design was inspired by ASP.NET Razor. Specifically it is: compact, expressive, and fluid: it minimizes the number of characters and keystrokes required in a file, and enables a fast, fluid coding workflow.
Play Framework is an open-source web application framework which follows the model–view–controller (MVC) architectural pattern. It is written in Scala and usable from other programming languages that are compiled to JVM bytecode, e.g. Java.
Internally, Play Framework is asynchronous from the bottom up. Play handles every request in an asynchronous, non-blocking way. The default configuration is tuned for asynchronous controllers.
Either use the fully-qualified name, i.e. @(item: Option[Item] = None,
violations: java.util.Set[javax.validation.ConstraintViolation[Item]] = new util.HashSet[javax.validation.ConstraintViolation[Item]]())
or add to your general template imports in Build.scala, like this:
val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings(
templatesImport += "javax.validation.ConstraintViolation"
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With