Successfully reported this slideshow.

Dive into Play Framework

1,962 views

Published on

A quick talk that was given during 2010 about the main features of Play! framework.

This was given to the development team at Evoolv, which has kickstarted the web development over Play! framework which turned out was a decent choice.

Published in: Technology, Education
  • Be the first to comment

Dive into Play Framework

  1. 1. Dive into Framework Maher Gamal
  2. 2. Key Features● Agile development workflow ( Save, Reload ! )● Stateless architecture● Clear error reporting● Reusable modules & plugins● Gets you up and running quickly !
  3. 3. Project Layout : play new proj1● proj1/app/controllers● proj1/app/models● proj1/app/views● proj1/conf/application.conf● proj1/conf/messages● proj1/conf/routes● proj1/lib● proj1/public● proj1/test
  4. 4. Routing : /conf/routes ● ExamplesGET /profile/view/{id} ProfileController.viewPOST /profile/save ProfileController.saveGET /{<ar|en>lang}/ HomeController.index* /{controller}/{action} {controller}.{action} ● Defining the URLs early, forces you to explore your website ● You can use annotations too (with the play-router module)
  5. 5. Controllers : /app/controllersimport play.mvc.Controller;public class ProfileController extends Controller { public static void view(Long id) { // ... renderText("123"); // or json, xml. renderTemplate("Users/show.html"); redirect("...."); HomeController.index(); // Does a redirect // ... }}
  6. 6. Models : /app/modelsimport play.db.jpa.Model;import javax.persistence.Entity;@Entitypublic class User extends Model { public String email; public String password;}
  7. 7. Validations : /app/modelsimport play.db.jpa.Model;import javax.persistence.Entity;import play.data.validation.*;@Entitypublic class User extends Model { @Email @Required public String email; @Required @MinSize(5) public String password;}
  8. 8. Validations : /app/controllersimport play.mvc.Controller;public class ProfileController extends Controller { public static void view(@Valid Profile profile) { render(profile); // or invoke the validation manually ! // validation.valid(profile) }}
  9. 9. Views : /app/views/app/views/ProfileController/view.html#{ifErrors} <ul class="error"> #{errors} <li>${error}</li> #{/errors} </ul>#{/ifErrors}
  10. 10. Views : /app/views/app/views/ProfileController/view.html#{extends main.html /}#{set title : Page Title /}#{set moreScripts} ...#{/set}/app/views/main.html<html> <head> <title>#{get title /}</title> #{get moreScripts /} </head></html>
  11. 11. Views : /app/views/app/views/main.html<html> <head> <title>#{get title /}</title> #{get moreScripts /} </head> <body> ... #{doLayout /} ... </body></html>
  12. 12. Jobs : /app/jobspublic class BootstrapJob extends Job { @Override public void doJob() { ... }}
  13. 13. Jobs : /app/jobs@OnApplicationStartpublic class BootstrapJob extends Job { @Override public void doJob() { ... }}
  14. 14. Jobs : /app/jobs@Every("1h") or @On("0 0 * * *")public class BootstrapJob extends Job { @Override public void doJob() { ... }}
  15. 15. Helper Libraries : play.libs.* ● MD5 , SHA1 , Base64 Encoding/Decoding ● Encryption , decryption , hashing ● File/Directory copying , deleting and I/O methods ● Image resizing , cropping and captcha generation ● Mail message preparation and sending ● OAuth Integration ● OpenID Integration ● HttpClient to call external web services ● XML Parsing
  16. 16. Running● play new proj1● play run proj1● play clean,run proj1● play netbeansify proj1● play help
  17. 17. Resources● Documentation ○ playframework.org/documentation ○ playframework.org/documentation/api/1.1.1/index.html● Community ○ playframework.org/community ○ play.lighthouseapp.com ○ groups.google.com/group/play-framework● Modules and Examples ○ playframework.org/modules ○ Check samples-and-tests directory in the release

×