Intro to Play Framework

Java Edition

James Ward ~ @_JamesWard

Create a New Play App

activator new

IDE Support

activator idea

Run the App

activator ~run

Open the App

http://localhost:9000

Testing

  • Based on JUnit
  • Unit Tests with Mocks
  • Functional Tests for Templates, Controllers, Router

Run All Tests Once

activator test

Run All Tests Continuously

activator ~test

Run One Test

activator "test-only my.namespace.MySpec"

Run Failed Tests

activator test-quick

Models


  • EBean for Java
  • JPA Annotations
  • Versioned Evolution Scripts

Forms


  • Controller: Bind request data to VO
  • View: Server-side Form Helpers

Asset Compilers

Unified Client/Server Development

  • assets/javascripts/foo.{js|coffee}
  • assets/stylesheets/foo.less
<script src='@routes.Assets.at("javascripts/foo.min.js")'></script>
Specify Dependencies in build.sbt
"org.webjars" %% "webjars-play" % "2.2.0",
"org.webjars" % "bootstrap" % "2.3.1"
Create Route for WebJarAssets Controller
GET     /webjars/*file              controllers.WebJarAssets.at(file)
Use a WebJar
<script src='@routes.WebJarAssets.at(WebJarAssets.locate("jquery.min.js"))'></script>

Reactive Requests