KEMBAR78
eXo Platform SEA - Play Framework Introduction | ODP
Vu Viet Phuong - PortalTeam Play Framework Introduction
Introduce key features of Play! framework Some great new ideas for Web Framework  Objective
Play! Framework Introduction Subject Demo sample applications
Play! Framework Introduction
Simple stateless MVC architecture No configuration: download, unpack and develop Integrated unit testing:  JUnit and Selenium support is included in the core Elegant API: rarely will a developer need to import any third party library - Play comes with all the typical stuff built-in Major differences
Uses Java but tries to push all the good things  from the frameworks based on scripting languages Get the best of the Java platform without  getting the pain of traditional Java web development Advantage
Very good documented and easy to use product - JavaDoc
- User guide
- Sample apps Full-stack application framework Introduce a completely new way to develop web apps Advantage
Database support : JDBC,  object-relational mapping using Hibernate (with the JPA API). Integrated cache support with easy use of the distributed memcached system if needed Straightforward web services consumption either in JSON or XML  Full-stack application framework
OpenID support for distributed authentication Ready to be deployed anywhere (application server, Google App Engine, Cloud, etc…) Image manipulation API Full-stack application framework
Build and deployment is all handled by Python scripts Introduce a new way to develop web apps Fix the bug and hit Reload Lifting away the Java EE constraints Test framework Easy to use
The Java platform is infamous for its low productivity Repeated and tedious compile-package-deploy cycles Hot code reloading and display of errors in the browser
- Play will detect changes and automatically reload them at runtime
- Stack traces are stripped down and optimized to make it easier to solve problems Fix the bug and hit Reload
It is a very different thing to write a generic and reusable Java library and to create a web application
An easy-to-develop and elegant stack aimed at productivity Java itself is a very generic programming language and not originally designed for web application development Traditional Java web development:
Slow development cycle, too much abstraction, configuration... Lifting away the Java EE constraints
JBoss Netty for the web server Hibernate for the data layer Groovy for the template engine The Eclipse compiler for hot-reloading Apache Ivy for dependency management Popular Java libraries
The conf/ directory for the application The $PLAY_PATH/framework/play-$version.jar All JAR files found in your application’s lib/ directory All JAR files found in the $PLAY_PATH/framework/lib/ directory Classpath settings
Play provides a built-in test framework for  unit testing and functional testing Tests are run directly in the browser By default all testing is done against  the included H2 in-memory database Testing framework
Extensions http://www.playframework.org/modules Download and installation
http://www.playframework.org/download
---> unpack, setup classpath ---> play! …. Some sample public websites Playapps.net, Zibbet Search, Masterbranch ... Resources
Demo
app/  -   the application’s core, split between models, controllers and views directories

eXo Platform SEA - Play Framework Introduction

  • 1.
    Vu Viet Phuong- PortalTeam Play Framework Introduction
  • 2.
    Introduce key featuresof Play! framework Some great new ideas for Web Framework Objective
  • 3.
    Play! Framework IntroductionSubject Demo sample applications
  • 4.
  • 5.
    Simple stateless MVCarchitecture No configuration: download, unpack and develop Integrated unit testing: JUnit and Selenium support is included in the core Elegant API: rarely will a developer need to import any third party library - Play comes with all the typical stuff built-in Major differences
  • 6.
    Uses Java buttries to push all the good things from the frameworks based on scripting languages Get the best of the Java platform without getting the pain of traditional Java web development Advantage
  • 7.
    Very good documentedand easy to use product - JavaDoc
  • 8.
  • 9.
    - Sample appsFull-stack application framework Introduce a completely new way to develop web apps Advantage
  • 10.
    Database support :JDBC, object-relational mapping using Hibernate (with the JPA API). Integrated cache support with easy use of the distributed memcached system if needed Straightforward web services consumption either in JSON or XML Full-stack application framework
  • 11.
    OpenID support fordistributed authentication Ready to be deployed anywhere (application server, Google App Engine, Cloud, etc…) Image manipulation API Full-stack application framework
  • 12.
    Build and deploymentis all handled by Python scripts Introduce a new way to develop web apps Fix the bug and hit Reload Lifting away the Java EE constraints Test framework Easy to use
  • 13.
    The Java platformis infamous for its low productivity Repeated and tedious compile-package-deploy cycles Hot code reloading and display of errors in the browser
  • 14.
    - Play willdetect changes and automatically reload them at runtime
  • 15.
    - Stack tracesare stripped down and optimized to make it easier to solve problems Fix the bug and hit Reload
  • 16.
    It is avery different thing to write a generic and reusable Java library and to create a web application
  • 17.
    An easy-to-develop andelegant stack aimed at productivity Java itself is a very generic programming language and not originally designed for web application development Traditional Java web development:
  • 18.
    Slow development cycle,too much abstraction, configuration... Lifting away the Java EE constraints
  • 19.
    JBoss Netty forthe web server Hibernate for the data layer Groovy for the template engine The Eclipse compiler for hot-reloading Apache Ivy for dependency management Popular Java libraries
  • 20.
    The conf/ directoryfor the application The $PLAY_PATH/framework/play-$version.jar All JAR files found in your application’s lib/ directory All JAR files found in the $PLAY_PATH/framework/lib/ directory Classpath settings
  • 21.
    Play provides abuilt-in test framework for unit testing and functional testing Tests are run directly in the browser By default all testing is done against the included H2 in-memory database Testing framework
  • 22.
  • 23.
  • 24.
    ---> unpack, setupclasspath ---> play! …. Some sample public websites Playapps.net, Zibbet Search, Masterbranch ... Resources
  • 25.
  • 26.
    app/ - the application’s core, split between models, controllers and views directories
  • 27.
    conf/ - application’s configuration files
  • 28.
    lib/ - optional Java libraries
  • 29.
    test/ - JUnit tests or as Selenium tests ~$ play new helloworld Project creation
  • 30.
    Translating incoming HTTPRequests into action calls /conf/routes * /clients/{id} Clients.show ---> GET /clients/1541
  • 31.
    ---> PUT /clients/abcd The default matching strategy /[^/]+/ User defined pattern /clients/{<[0-9]+>id} Router
  • 32.
    Routes priority :first available GET /clients/all Clients.listAll
  • 33.
    GET /clients/{id} Clients.show Serving static resources staticDir: mapping GET /public/ staticDir:public staticFile: mapping GET /home staticFile:/test.html Reverse routing: generate some URL map.put(&quot;id&quot;, 1541);
  • 34.
    String url =Router.reverse(&quot;Clients.show&quot;, map).url; // GET /clients/1541 Router
  • 35.
    Variables and scripts: GET ${context} Secure.login Setting content types -> determines which view template file GET /index.xml Application.index(format:'xml') GET /index.{format} Application.index Router
  • 36.
    The last partof a route definition is the Java call A Controller should be defined in the controllers package and must be a subclass of Controller class The action method must be a public static void method Controller
  • 37.
    Using the paramsmap From the action method signature JPA object binding : loads the matching instance from the DB before editing it public static void save(User user) { user.save(); // ok with 1.0.1 } user.id = 1 &user.name=morten &user.address.id=34 &user.address.street=MyStreet Retrieving HTTP parameters
  • 38.
    There is noequivalent to the Servlet API forward An HTTP request can only invoke one action Filter ~ Interceptions @Before @After @Catch @Finally Session and Flash scope Using the Cookie mechanism Compare to J2EE
  • 39.
    If you haveused Hibernate or JPA before you will be surprised by the simplicity added by Play CRUD module help quickly generate a basic administration area Secure, validation framework, JSON and XML parsers, OpenID support, full embedded testing framework … Make life easier
  • 40.
    Unit test Aunit test is written using JUnit Functional test Accessing directly the controller objects Selenium test Running it in an automated browser Test your application