====== Play! framework ====== The High Velocity Web Framework For Java and Scala : [[http://www.playframework.org/|www.playframework.org]] C'est le Symfony (Php) de Java ! Ce framework n'est pas basé sur J2EE, il embarque directement sont serveur ([[http://www.jboss.org/netty|Netty]]). Play Framework is the High Velocity Web Framework for Java and Scala. Play is based on a lightweight, stateless, web-friendly architecture. Built on [[/informatique/java/frameworks/akka|Akka]], Play provides predictable and minimal resource comsumption (CPU, memory, threads) for highly-scalable applications. > [[/informatique/java/frameworks/play_framework_old|Ancienne page Play! Framework]] Play! utilise les frameworks * [[https://www.typesafe.com/community/core-tools/activator-and-sbt|Typesafe Activator and sbt]] * Activator includes the sbt build tool, a quick-start GUI, and a catalog of template applications. Activator’s quick-start UI walks you through Typesafe Reactive Platform tutorials and is a hub for developers wanting to build Reactive applications. Common development patterns are presented through reusable templates that are linked to in-context tutorials * sbt is an interactive build tool with customizable build tasks and an "execute-task-on-file-change" feature * [[/informatique/java/frameworks/akka|Akka]] pour son fonctionnement asynchrone. * [[https://www.playframework.com/documentation/2.4.x/JavaAkka|Integrating with Akka]] * [[https://ebean-orm.github.io/|Ebean]] a Java ORM ===== Hébergement sur le web ===== [[http://stackoverflow.com/questions/9643751/what-cloud-platform-supports-playframework|what-cloud-platform-supports-playframework]] * [[https://devcenter.heroku.com/categories/java|Heroku]] * [[http://playframework-cloud.com|playframework-cloud]] by Clever Cloud * https://www.cloudbees.com/ * [[https://scalingo.com/java-play-framework-hosting|scalingo]] * [[https://www.openshift.com/pricing/plan-comparison.html|OpenShift.com]] (//[[https://github.com/opensas/play2-openshift-quickstart|Play framework 2.0 quickstart for Openshift]]//) ===== Community ===== * [[https://groups.google.com/forum/#!forum/play-framework|Google group]] * [[https://stackoverflow.com/questions/tagged/playframework|Stackoverflow]] ===== doc ===== Présentations: * [[http://joshpadnick.com/wp-content/uploads/2013/11/Play-Framework.pdf|Intro to Play Framework & Modern Java Web App Development]] by Josh Padnick, November 9, 2013 * [[https://www.quora.com/Which-is-better-Play-Framework-or-Spring-MVC-How-should-I-decide-what-to-use|Which is better, Play Framework or Spring MVC? How should I decide what to use?]] * [[https://www.youtube.com/watch?v=8z3h4Uv9YbE|The Play Framework at LinkedIn: Productivity and Performance at Scale]] (2013) * [[https://www.youtube.com/watch?v=4b1XLka0UIw|Play Framework & SF Scala: Jim Brikman, Composable Applications in Play]] (2014) - Jim shows how to build an equivalent of Facebook's BigPipe in Play, where components of a page are delivered in parallel, decreasing latency dramatically, especially for mobile. (Async, Promise, Enumerator, Stream) Tutoriels: * [[https://github.com/jamesward/play2torial/blob/master/JAVA.md|Play2torial for Java]] by James Ward * [[http://digitalsanctum.com/2012/05/26/play-framework-2-tutorial-introduction/|Play Framework 2 Tutorial: Introduction]] * Anand Kumar Singh: * [[http://blog.knoldus.com/2014/10/04/tutorial-1/|Tutorial #1: Getting started with Play Framework 2.3.4]] * [[http://blog.knoldus.com/2015/03/23/play-tutorial-2/|Tutorial #2: Using WebJars, jQuery, Bootstrap & Bootswatch with Play application]] * [[https://github.com/cloudspace/play_framework_tutorial|cloudspace/play_framework_tutorial]] * [[https://github.com/3monkeys/play.rules/tree/master/livre.play.deux|Livre Play!]] par 3Monkeys (2013) * mariussoutier / PlayBasics [[https://github.com/mariussoutier/PlayBasics|code for his tutorial series about Play Framework 2.x]] * [[http://www.playframework.com/documentation/2.1.1/JavaGuide1|Tutorial zentask]] and [[https://github.com/remylab/play-zentask|the code]] * [[http://luiscamilo.com/2015/07/27/play-framework-2-4-x-modulesub-project-assets/|Play Framework 2.4.x module/sub-project assets]] Autres: * [[http://adrianhurt.github.io/play-bootstrap/|Play-Bootstrap]] Play Framework library for Bootstrap * [[https://github.com/adrianhurt/play-api-rest-seed|Play API REST Template (Play 2.4 - Scala)]] * [[https://github.com/adrianhurt/play-multidomain-seed|Multidomain Seed (Play 2.4 - Scala)]] * [[https://github.com/yesnault/PlayStartApp|PlayStartApp]] Starting APP Play Framework 2.x with Signup, Signin, Reset password, Change Email from Settings... Common uses cases * [[http://www.typesafe.com/activator/template/play2-crud-activator|Typesafe Activator Play + Java + CRUD]] *[[https://github.com/typesafehub/activator-computer-database-java|Computer Database Java]] This is a classic Play CRUD application, backed by a JDBC database. It demonstrates DB access with Ebean, classic pagination, and integration with a CSS framework (Twitter Bootstrap). * [[https://github.com/franzgranlund/dtapp|Play! Framework 2.0 + DataTables + Server-side processing]] with jquery.dataTables * [[https://github.com/hakandilek/publicplay|PublicPlay]] is yet another forum application built with the play framework Encore: * Auth (Authentication/Authorization): * [[https://github.com/joscha/play-authenticate|play-authenticate]] an extensible authentication plugin for Play! Framework 2 (Java) * [[https://github.com/leleuj/play-pac4j|play-pac4j]] Oatuh 1 & 2, CAS, ... * [[https://github.com/jaliss/securesocial|SecureSocial for Play 2]] (Scala & Java) * [[https://github.com/mohiva/play-silhouette|play-silhouette]] (Scala only), Silhouette is an authentication library for Play Framework applications that supports several authentication methods, including OAuth1, OAuth2, OpenID, Credentials, Basic Authentication, Two Factor Authentication or custom authentication schemes. http://silhouette.mohiva.com * [[http://deadbolt.ws|Deadbolt]], only Authorization, no Authentication * [[https://github.com/hakandilek/play2-crud|play2-crud]] Simple CRUD & DAO implementation for play2. * [[https://github.com/digiPlant/play-scalr|Image Resizing for Play Framework 2]] * [[https://github.com/brikis98/ping-play|BigPipe streaming for the Play Framework]], The ping-play project brings BigPipe streaming to the Play Framework. It includes tools for * a) splitting your pages up into small "pagelets", which makes it easier to maintain large websites, and * b) streaming those pagelets down to the browser as soon as they are ready, which can significantly reduce page load time. * [[https://github.com/iheartradio/play-swagger|Swagger API spec generator for Play]], a library that generates swagger specs from route files and case class reflection, no code annotation needed * [[https://github.com/huljas/play-messages|Localization tool for play framework]], this module gives you a tool for localizing your application * Chat: * [[https://github.com/matthiasn/sse-chat|SSE Chat]], a Chat example app using [[/glossaire/SSE|Server Sent Events (SSE)]] plus REST calls * [[http://vyazici.blogspot.fr/2012/03/chat-application-with-play-framework.html|Chat Application with Play Framework and KnockoutJS]] and [[https://github.com/vy/play-chat|the code]] * [[https://github.com/BuggleInc/webPLM|Web Interface of the PLM]] * [[https://github.com/poornerd/play-aloha|play-aloha]] - Play! Framework example project with [[http://​www​.aloha​-edi​tor​.org/|Aloha WYSIWYG HTML Editor]] * [[https://github.com/choreo/play-thymeleaf|play-thymeleaf]]: a Play framework **1.x** module to use Thymeleaf as a template engine Livres: * [[https://www.packtpub.com/web-development/learning-play-framework-2|Learning Play! Framework 2]], Andy Petrella, March 2013 * [[https://www.packtpub.com/web-development/play-framework-essentials|Play Framework Essentials]], Julien Richard-Foy, September 2014 ===== En vrac ===== ==== Activator & SBT ==== Typesafe Activator Templates: https://www.typesafe.com/activator/templates Les dossiers pour le cache: * Les packages chargés sont stockés dans ~/.ivy2/cache * Les fichiers SBT sont stockés dans ~/.sbt Après installation, création et run du projet essai01 (activator new essai01 play-java) le volume utilisé sur le disque est de 822,6 Mo: * activator-dist-1.3.7: 7 657 éléments, 601,4 Mo * .ivy2: 1 384 éléments, 120,8 Mo * .sbt: 115 éléments, 90,6 Mo * essai01 (play-java template): 323 éléments, 9,8 Mo Un run ressemble à: $ activator run [info] Loading project definition from /home/cyrille/Taf/CEFIM_2016_Java/essai01/project [info] Set current project to essai01 (in build file:/home/cyrille/Taf/CEFIM_2016_Java/essai01/) --- (Running the application, auto-reloading is enabled) --- [info] p.c.s.NettyServer - Listening for HTTP on /0:0:0:0:0:0:0:0:9000 (Server started, use Ctrl+D to stop and go back to the console...) Puis à la visite de http://localhost:9000/: [info] Compiling 6 Scala sources and 2 Java sources to /home/cyrille/Taf/CEFIM_2016_Java/essai01/target/scala-2.11/classes... [info] 'compiler-interface' not yet compiled for Scala 2.11.6. Compiling... [info] Compilation completed in 6.524 s [info] - play.api.Play - Application started (Dev) === Run un sous-projet === Par exemple dans SecureSocial2 il y a les sous-projets javaDemo et scalaDemo. Pour les runner: $ activator 'project javaDemo' run === Changer le port HTTP ou DEBUG === Run avec le serveur http écoutant le port 9001: $ activator "~run 9001" Pour changer le port du debuggage (JPDA Port) $ activator -jvm-debug 9999 ~run ==== Websocket & Akka actor ==== Chat: * [[https://devcenter.heroku.com/articles/play-java-websockets|Using WebSockets on Heroku with Java and the Play Framework]] - There are 3 important pieces to the interaction that takes place here: a controller method that returns a WebSocket object, a JavaScript method that opens that WebSocket, and an Akka actor that sends the payload across that WebSocket every second. Let’s explore each * And the scalable version [[https://devcenter.heroku.com/articles/play-java-websockets-advanced|Writing Scalable WebSocket Applications on Heroku with Java and the Play Framework]] * En Scala (pour inspiration) * [[https://github.com/mandubian/play-actor-room|play-actor-room]] - A Room manager for Play Framework 2.2 based on Websockets & Bots * [[http://www.typesafe.com/activator/template/clustered-chat|Clustered Chat with Play Framework, Websockets and Akka Cluster]] Map update: * [[https://playlatam.wordpress.com/2012/04/10/playing-2-0-with-twitter-bootstrap-websockets-akka-and-openlayers/|Play!ing (2.0) with Twitter Bootstrap, WebSockets, Akka and OpenLayers]] * [[http://www.objectify.be/wordpress/?p=341|Play 2, Akka, Websockets, Backbone.js and Leaflet – just having fun, really]] ==== Forms ==== * [[https://github.com/murz/play-jqvalidate|play-jqvalidate]] Client-side form validation based on your Play framework model annotations. Accesing directly the request body: package controllers; import play.mvc.*; import views.html.*; import java.util.Map; public class JavaPoster extends Controller { public static Result save() { final Map values = request().body().asFormUrlEncoded(); final String name = values.get("java_name")[0]; final String surname = values.get("java_surname")[0]; return ok(index.render(String.format("You are %s, %s",surname, name))); } } Or using a DynamicForm: package controllers; import play.mvc.*; import views.html.*; import play.data.DynamicForm; public class JavaPoster extends Controller { public static Result save() { final DynamicForm form = form().bindFromRequest(); final String name = form.get("java_name"); final String surname = form.get("java_surname"); return ok(index.render(String.format("You are %s, %s",surname, name))); } }