I am using Play Framework 2.0.1. I have created a Java application using the "play new" command. By default, two views are created: index.scala.html and main.scala.html
I've done a few sample tutorial apps that allow me to render those views. However, when I add a new view (by default in app/views/), I get a compilation error that it cannot be found:
public static Result getAllCars() {
List<Car> cars = Car.getAllCars();
return ok(simpleCarView.render(cars));
}
I can do
import views.html.index;
import views.html.main;
but not
import views.html.simpleCarView;
Error in console:
cannot find symbol
[error] symbol : variable simpleCarView
[error] location: class controllers.Application
I've tried adding scala.html views in the file directory and from within eclipse, but for some reason they are not found. I've also tried restarting the default Netty server.
Any ideas on what is causing this?
A Play Scala template is a simple text file that contains small blocks of Scala code. Templates can generate any text-based format, such as HTML, XML or CSV. The template system has been designed to feel comfortable to those used to working with HTML, allowing front-end developers to easily work with the templates.
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.
Razor minimizes the number of characters and keystrokes required when writing a view template, and enables a fast, fluid coding workflow.
To ensure that languages are resolved correctly, specify the languages your app supports using the resConfigs property in the module-level build.
The views are not compiled by Eclipse but can be seen by eclipse after they're compiled by Play as long as the target\scala-2.9.1\classes_managed directory is in your eclipse project build path.
Try running "play compile" on the command line (or just "compile" if you're already in the play console) and then refreshing your project within eclipse (select the project and hit F5)
For you IntelliJ 12 users out there: I upgraded to Play 2.1 which broke my Play IntelliJ Support plugin. This caused IntelliJ to not recognise:
import views.html.*;
so when hitting cmd + o
to optimize my imports it was removed.
This resultet in a compilation error when running play clean compile
since
the views were not imported:
[error] symbol : variable index
[error] location: class controllers.Application
[error] return ok(index.render());
[error] ^
[error] 1 error
[error] (compile:compile) javac returned nonzero exit code
[error] application -
So I uninstalled the plugin, restarted IntelliJ and viola everything works like a charm!
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