- Play 2.0 is a web framework for Java and Scala that simplifies development by embracing HTTP rather than fighting it
- It takes a new approach to building web apps in Java by not being built on top of servlet APIs and using an asynchronous programming model
- Developing, testing, and deploying a Play app locally and to CloudFoundry involves creating a project, running it locally, and pushing the compiled code to CloudFoundry which automatically detects and supports Play apps
10. Play 2.0 Overview
• Web framework written in Java and Scala
• Not built on top of Servlet APIs
11. Play 2.0 Overview
• Web framework written in Java and Scala
• Not built on top of Servlet APIs
• Statically typed MVC Architecture
12. Play 2.0 Overview
• Web framework written in Java and Scala
• Not built on top of Servlet APIs
• Statically typed MVC Architecture
• Asynchronous HTTP Programming Model
13. Play 2.0 Overview
• Web framework written in Java and Scala
• Not built on top of Servlet APIs
• Statically typed MVC Architecture
• Asynchronous HTTP Programming Model
• Client side templating in Scala
14. Play 2.0 Overview
• Web framework written in Java and Scala
• Not built on top of Servlet APIs
• Statically typed MVC Architecture
• Asynchronous HTTP Programming Model
• Client side templating in Scala
• Server side code in Java or Scala
15. Anatomy of a Play 2.0
Application
-app App sources
-conf Configuration files
-dist Zip file deployed to Cloud Foundry
-logs Logs
-project sbt project files
-public public assets( js, css)
-target Generated sources
16. MVC
• Model : Domain Object Models map to a
persistence store
• Views :Rendered content using templates
• Controller : Routes Http requests using ActionS
17. Play Architecture
• Built as an extension of JBoss Netty Server
• All the requests are Asynch -- using nio
• Core Play is a pure Scala app which runs in
a JVM
• Stateless on the Server side
21. Lifecycle of a Play app
in CloudFoundry
Install Play
Develop/Test Locally
22. Lifecycle of a Play app
in CloudFoundry
Install Play
$play new myapp
Develop/Test Locally [myapp]$run
23. Lifecycle of a Play app
in CloudFoundry
Install Play
$play new myapp
Develop/Test Locally [myapp]$run
Deploy on Cloud
Foundry
24. Lifecycle of a Play app
in CloudFoundry
Install Play
$play new myapp
Develop/Test Locally [myapp]$run
Deploy on Cloud $vmc push --path=dist/
myapp.zip
Foundry
27. App Structure : Router
# Home page
GET / controllers.Application.index()
# Map static resources from the /public folder to the /assets URL
path
GET /assets/*file controllers.Assets.at(path="/public", file)
# Tasks
GET /tasks controllers.Application.tasks()
POST /tasks controllers.Application.newTask()
POST /tasks/:id/delete controllers.Application.deleteTask(id: Long)
28. App Structure : Controller
public class Application extends
Controller {
public static Result index() {}
public static Result tasks() {}
public static Result newTask() {}
public static Result deleteTask(
Long id) {}
}
29. App Structure : Model
@Entity
public class Task extends Model {
@Id
public Long id;
@Required
public String label;
public static Finder<Long,Task>
find = new Finder(...);
public static void create(Task task)
{
task.save();
}
}
30. AppStructure :View
• Scala based template
• Compiled into a scala function with render
method
@(tasks: List[Task], taskForm: Form[Task])
@import helper._
@main("Todo list") {
<h1>@tasks.size() task(s)</h1>
....
36. Summary
• Play 2.0 takes a new approach to Web app
development in Java world
37. Summary
• Play 2.0 takes a new approach to Web app
development in Java world
• Simplifies the development cycle
38. Summary
• Play 2.0 takes a new approach to Web app
development in Java world
• Simplifies the development cycle
• Frameworks should not fight HTTP but
embrace it