Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Newly created scala.html views are not being recognized in Play Framework 2.x

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?

like image 346
Matthew Steven Monkan Avatar asked May 16 '12 20:05

Matthew Steven Monkan


People also ask

What is Scala HTML?

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.

Which component is responsible for building play framework?

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.

Which technique enables a fast coding workflow minimizes the number of characters and keystrokes required in a file?

Razor minimizes the number of characters and keystrokes required when writing a view template, and enables a fast, fluid coding workflow.

Which property is used to specify supported languages of the play application?

To ensure that languages are resolved correctly, specify the languages your app supports using the resConfigs property in the module-level build.


2 Answers

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)

like image 194
InPursuit Avatar answered Sep 21 '22 08:09

InPursuit


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!

like image 37
jakob Avatar answered Sep 21 '22 08:09

jakob