Pergunta

I just migrated across to Play Framework 2.1-RC1 from 2.0 on an existing project and for some reason I'm now having to cast everything to Scala classes from Java classes when I render the views. (Obviously I'm using Play in a Java project rather than a Scala project)

Below is an example error...

render(java.lang.String,scala.collection.immutable.List<models.User>) in views.html.list cannot be applied to (java.lang.String,java.util.List<models.User>)

And the top line of my view...

@(message: String, users : List[models.User])

From this I surmise that for some reason classes aren't being automatically cast from java.util.List to the scala equivalent. I'm a Java guy, not a Scala guy at this stage so I may be doing something stupid.

Example code that calls render...

public static Result list() {
        List<User> users = MorphiaManager.getDatastore().find(User.class).asList();
    System.out.println("about to try to display list of " + users.size() + " users");
        return ok(list.render("Welcome", msgs));
    }

Build.scala below

import sbt._
import Keys._
import PlayProject._

object ApplicationBuild extends Build {

    val appName         = "blah-worker"
    val appVersion      = "1.0-SNAPSHOT"

    val appDependencies = Seq(
  // Play framework dependencies
  javaCore, javaJdbc, javaEbean,
  // Add your project dependencies here,
  "org.apache.camel" % "camel-core" % "2.10.0",
  "org.apache.camel" % "camel-jms" % "2.10.0",
  "org.apache.camel" % "camel-mail" % "2.10.0",
  "org.apache.camel" % "camel-jackson" % "2.10.0",
  "org.apache.camel" % "camel-gson" % "2.10.0",
  "org.apache.activemq" % "activemq-core" % "5.6.0",
  "org.apache.activemq" % "activemq-camel" % "5.6.0",
  "org.apache.activemq" % "activemq-pool" % "5.6.0",
  "com.google.code.morphia" % "morphia" % "0.99.1-SNAPSHOT",
  "com.google.code.morphia" % "morphia-logging-slf4j" % "0.99",
  "cglib" % "cglib-nodep" % "[2.1_3,)",
  "com.thoughtworks.proxytoys" % "proxytoys" % "1.0",
  "org.apache.james" % "apache-mime4j" % "0.7.2",
  ("org.jclouds" % "jclouds-allblobstore" % "1.5.0-beta.4").exclude("com.google.guava", "guava").exclude("org.reflections", "reflections"),
  ("org.reflections"                  %    "reflections"              %   "0.9.7").exclude("com.google.guava", "guava").exclude("javassist", "javassist")
)

val main = play.Project(appName, appVersion, appDependencies).settings(
  // Add your own project settings here
  resolvers += "Morphia repo" at "http://morphia.googlecode.com/svn/mavenrepo/",
  resolvers += "CodeHaus for ProxyToys" at "http://repository.codehaus.org/",
  checksums := Nil
)

}
Foi útil?

Solução 2

Figured it out, I hadn't updated one of the imports on Build.scala.

Specifically...

import PlayProject._

should be updated to...

import play.Project._

which is also detailed in the migration guide (but I missed it): https://github.com/playframework/Play20/wiki/Migration

Outras dicas

Are you missing the new 'javaCore' dependency? It is required for Java projects using Play 2.1. Look here for migration details:

https://github.com/playframework/Play20/wiki/Migration

I'm not sure if it will fix you problem but can you try adding this import:

import scala.collection.JavaConversions.*;

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top