Académique Documents
Professionnel Documents
Culture Documents
Brian Clapper
Founder: PHASE
@brianclapper
bmc@ardentex.com
Talk Outline
What is Play?
Lightweight
Productive
Fast
Type Safe
Deployment
Also lightweight.
No WAR file necessary for deployment.
No additional container required, because Play is bundled
with Netty.
Can deploy the directory, as is, as long as Play is installed
on server.
Play can bundle up a self-contained zip file with all
necessary components.
Theres a plug-in to generate a WAR file, if you must
have one.
Bundled Technologies
Getting started
Getting started
Type:
$ play new myapp
[verbose output omitted]
My Usual Layout
My Usual Layout
I also:
delete app/public/stylesheets/main.css (which will
be served statically), and
add app/assets/stylesheets/main.less (which will
be auto-compiled to a CSS file)
Models
Models: Scala
Play 2.0.x for Scala ships with Anorm: thin layer over raw
SQL.
Has the advantages of direct SQL:
Close to the actual database
No intervening ORM language to learn
Models: Java
Controllers
A simple hello, world controller, in Java:
public class MyApp extends Controller {
public static Result index() {
return ok("Hello, world!")
}
}
In Scala:
object Application extends Controller {
def index() = Action {
Ok("Hello, world!")
}
}
Controllers
Controllers
With a redirect, in Java:
Controllers
Now, with template-rendering goodness. In Java:
public class MyApp extends Controller {
public static Result index() {
return ok(index.render());
}
}
In Scala:
object Application extends Controller {
def index() = Action {
Ok(views.html.index());
}
}
GET
controllers.Application.index
POST
GET
GET
/sign-in
/login
/logout
controllers.Auth.authenticate
controllers.Auth.login
controllers.Auth.logout
GET
POST
GET
POST
GET
GET
GET
POST
GET
/sites
/sites/list
/site/new
/site/create
/site/:id/edit
/site/$id<\d+>
/site/$id<\d+>/json
/site/$id<\d+>
/sites/download
controllers.SiteController.index
controllers.SiteController.list
controllers.SiteController.makeNew
controllers.SiteController.create
controllers.SiteController.edit(id: Long)
controllers.SiteController.show(id: Long)
controllers.SiteController.showJSON(id: Long)
controllers.SiteController.update(id: Long)
controllers.SiteController.download
/site/:id/delete
controllers.SiteController.delete(id: Long)
Templates
Simple template
@(currentUser: User)
@main("Youve logged in!", currentUser) {
<div class="todo-items">
Your to-do items follow.
<ul>
@for(item <- currentUer.toDoItems) {
<li>@item.text()</li>
}
</ul>
</div>
}
Speaking of questions