简体   繁体   中英

play framework help in views

While writing the javatodolist application for Play, I get an error from part "The application template"

reference to Form is ambiguous; it is imported twice in the same scope by import play.data._ and import play.api.data._

My index.scala.html is at http://nopaste.info/f10c386a02.html

And here is the error

The exception that you printed

reference to Form is ambiguous; it is imported twice in the same scope by import play.data._ and import play.api.data._

means that there are two classes with name Form one under package play.data._ , the other one under the package play.api.data._ I would recommend that you explicitly do your imports that means import just classes you would use.

Play Framework offers a Java and Scala API. Clearly, you want the Scala API, but it looks like you've added both to your classpath and imported both.

Here is the Java version of Form in the play.data package. Here is the Scala version of Form in the play.data.api package.

Get rid of the Java stuff, and you should be fine.

After having read the comments appended to the question, I got it working by qualifying the version of Form the view needs (the one from play.data) as in the following example:

@(myForm: play.data.Form[form.MyFormClass])

I guess that this behaviour is due to the fact that I am developing a Play application in java while the views are using the Scala API.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM