Play 2.0 Java: Can't pass List into template

2019-07-19 19:50发布

I am trying to pass a list of questions into a template in Play 2.0.

The controller code looks like this:

List<Question> questions = Question.findAll();
return ok(questions.render("Here are all the questions", questions));

The Template constructor looks like this

 @(message: String, questions: List[Question])

The template file is called questions.scala.html

I also use the questions list like this later in the template:

@questions_list(questions)

and the constructor for `questions_list.scala.html) looks like this:

@(questions: List[Question])

I am getting the compile error:

cannot find symbol [symbol: method render(java.lang.String,
java.util.List<models.Question>)] 
[location: interface java.util.List<models.Question>]

I have tried cleaning and recompiling with no luck? Does anybody see whats wrong here?

1条回答
聊天终结者
2楼-- · 2019-07-19 19:57

OK so the problem was a naming collision between my template and the variable name I was assigning to the List<Question>. I think I may start naming my templates with uppercase to more properly illustrate that that they are classes when I am using them in controllers.

查看更多
登录 后发表回答