2. First step
● Download PlayFramework from www.
playframework.com/download
● Add corresponding path to PATH
● Check if it works calling
>play help
3. Creating and running an Application
Navigate to your projects directory, and type
>play new application-name
>cd applicaiton-name
>play ~run
Open http://localhost:9090 in your favourite
browser (if your favourite browser is IE - open
it in Chrome ;)
4. Generated dirs structure
app
→ Application sources
└ assets
→ Compiled asset sources (stylesheets and javascripts)
└ controllers
→ Application controllers
└ models
→ Application business layer
└ views
→ Templates
build.sbt
→ Application build script
conf
→ Configurations files and other non-compiled resources (on classpath)
└ application.conf
└ routes
→ Main configuration file
→ Routes definition
public
→ Public assets
└ stylesheets
→ CSS files
└ javascripts
→ Javascript files
└ images
→ Image files
project
→ sbt configuration files
└ build.properties
└ plugins.sbt
lib
logs
→ sbt plugins including the declaration for Play itself
→ Unmanaged libraries dependencies
→ Standard logs folder
└ application.log
target
→ Marker for sbt project
→ Default log file
→ Generated stuff (including generated sources out of scala views)
└ scala-2.10.0
test
→ source folder for unit or functional tests
5. Basic play console commands
Workflow commands:
>play compile
>play run
>play test
>play clean-all
>play debug
>play eclise #generates eclipse project to use with ScalaIde 3.0.2
auto triggering (as in SBT)
>play ~ compile|run|test
6. Application development
● Global Application Object
- can control life-time events in an app
● Controllers
- do hard work around HTTP requests
● Routing
- binds requested URLs with particular Controllers
● Predefined results
● Sessions and Flashes
● Async results
9. Views
● Are in 90% in HTML + Scala-like expression
● Are compiled to Scala Objects
● View class is actually a … method body
We can create a reusable layout of a webapp:
views/templates/tasks.scala.html
and use it to form result content
views/tasks/list.scala.html
10. Models (DAOs and Entities)
We need a dependency for MySQL JDBC connector
in Build.scala we add
"mysql" % "mysql-connector-java" % "5.1.18",
in application.conf we add (to see SQL stmnts) :
db.default.logStatements=true
More at
http://www.playframework.com/documentation/2.1.x/ScalaDatabase
11. Models (DAOs and Entities)
import play.api.Play.current //imports current application
object into scope
import play.api.db._ //imports DB api (facade for JDBC)
//Retreiving connection
val ds = DB.getDataSource()
//lub
val connection = DB.getConnection()
//lub
DB.withConnection("default") { conn =>
// do whatever you need with the connection
}
… so let’s create an Entity and DAO and do some coding
12. … after coding - time to sum up
●
●
●
●
●
●
●
●
Native JSON and XML support
Powerful routing syntax
Web Services client (sync, async)
Build in translations management
Asynchronous HTTP programming
Less/CoffeScript support
ClosureCompiler/RequireJS support
many many more ;)