Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

An Introduction to Play 2 Framework

2,975 views

Published on

Apresentação de João Ferreira para o 19º encontro PT.JUG.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

An Introduction to Play 2 Framework

  1. 1. An Introduction to Play 2 Framework
  2. 2. Who am I? ● João Ferreira (@jtjeferreira) ● 5 years professional experience in backend & frontend development with Java, C# and Javascript ● Currently working @ E.Near, developing a scala applications
  3. 3. Outline ● Play framework features ● Play application anatomy ● Play MVC ● Form handling
  4. 4. What this presentation is NOT about ● Scala introduction ● How to bootstrap a Play Application ● How to use Play for Java
  5. 5. State of Java Web Frameworks Map[String,Object]
  6. 6. Play Features ● Type-safety ● Short feedback cycles ● Async programming
  7. 7. Play application anatomy app → Application sources └ assets → Compiled asset sources └ stylesheets → Typically LESS CSS sources └ javascripts → Typically CoffeeScript sources └ 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 → Main configuration file └ routes → Routes definition public → Public assets └ stylesheets → CSS files └ javascripts → Javascript files └ images → Image files project → sbt configuration files └ build.properties → Marker for sbt project └ plugins.sbt → sbt plugins including the declaration for Play itself lib → Unmanaged libraries dependencies test → source folder for unit or functional tests
  8. 8. Play MVC ● Model: scala classes ● View: twirl templates ● Controllers: route file + action generator methods
  9. 9. Play MVC - Controllers ● Controller ○ has Action generating methods ● Action (Request =>Result) ○ handles a request and generates a result
  10. 10. Play MVC - Controllers val ok = Ok("Hello world!") val notFound = NotFound val pageNotFound = NotFound(<h1>Page not found</h1>) val badRequest = BadRequest(views.html.form(formWithErrors)) val oops = InternalServerError("Oops") val anyStatus = Status(488)("Strange response type")
  11. 11. Play MVC - Controllers ● Route file ● Reverse Routing
  12. 12. Play MVC - Views ● Uses a scala-based language (Twirl) for the template language ● Templates are compiled to scala functions
  13. 13. Play MVC - Views ● Templates being simple functions gives us: ○ “taglibs” ○ “master templates”
  14. 14. Forms support- login use case Login Form userLoginForm: Form[UserLogin] user: text pass: text POST /login user=a pass=b Do stuff and replyLogin Success userLogin:UserLogin user: a pass: b userLoginForm.bindFromRequest userLoginForm.fold( errorFunc, successFunc ) login.scala.html loginSuccess.scala.html
  15. 15. The END

×