Features

Learn about different features of the Play framework.

Controllers, views and forms

Much like in Grails, controllers define the actions that can take place and the views, which are used.

Scala has functions that correspond to HTTP codes such as OK:

  • Success: Return ok(…)
  • Error: Return badRequest(…)

Views are based on templates. The default template language is Scala-based. For example, here’s an HTML page with a title that shows the environment’s user and the date:

@(title: String)
@import play.api.Play.current
<!DOCTYPE html>
<html>
<head>
  <title>@title</title>
</head>
<body>
user: @current.configuration.getString("environment.user"),
date: @(new java.util.Date().format("yyyy-MM-dd HH:mm"))
</body>
</html>

The first line of the file is much like a parameter list for the view template.

ORM

Play does not include an ORM solution like Grails does. You will need to include your own such as Squeryl to interface with a database.

Play 1.x

Play was radical when it came out. It used a dynamic development cycle (automatic compile & reload), it was containerless, and Play used actor-based asynchronous threading. It started out without Scala and even supported Python at one point. However, Play 2.0 is a different animal.

Play 2.0

Play 2.0 was released in February 2012. Play 2.0 added a lot of features including the sbt build tool, the (Akka) library for concurrency, and concentrated more on the Scala language. It has the following features:

  • Development console for RAD.
  • Type-checked all the way (route files, templates, and JavaScript).
  • Support for asynchronous programming techniques (webSockets, streaming, Comet and Eventsource, Akka).
  • Support for front end tech: LESS, Clojure, require.js, and coffeescript.
  • Functional test runner
  • Web helpers (async HTTP client, form validation, Oauth, ORM, etc.)

Play is built on Netty, akka, Java, Scala, and HTML5 web sockets. Play is extensible; you can make your own templating/routing implementation. Java and Scala can coexist. Play has a huge community and plugins and the ability to test with a mock browser and in-memory database.

Getting started

It’s very easy to get started with Play by going to the Lightbend technologies page and downloading a starter project. There are many projects in both Java and Scala.

Get hands-on with 1400+ tech skills courses.