Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

imported package is not available in Play! framework template

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?

like image 296
deamon Avatar asked Jan 11 '13 16:01

deamon


People also ask

What is twirl 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.

What is play framework in Scala?

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.

Is Play framework asynchronous?

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.


1 Answers

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"
)
like image 196
Marius Soutier Avatar answered Oct 06 '22 10:10

Marius Soutier