GRENOBLE

              Play framework (V1) :
     simplicité et productivité au service du
                développement WEB en Java

                 Xavier NOPRE – 12/02/2013
Préambule > Sondage

    Développeur Java ?

    Qui connait Play Framework ?
    Qui utilise Play Framework ?
        V1 ?
        V2 ?


    Précision …



    Play Framework 1.2.5 - http://www.playframework.com/ - Xavier NOPRE – 12/02/2013
Introduction
    Framework WEB complet
    Pour des développeurs pour des développeurs
    Pour une approche + simple et + rapide (vs JEE ou Spring)
    Constitué de composants choisis (JPA, Hibernate, …)
    Architecture Model View Controller
    Rechargement à chaud en mode "dev"
    Présentation des erreurs "serveur" dans la page HTML
     (explication et extrait de code)
    Stateless & REST
    Basé sur des conventions
                          Productivité !
    Play Framework 1.2.5 - http://www.playframework.com/ - Xavier NOPRE – 12/02/2013
Installation & démarrage
    Téléchargement play-1.2.5.zip :
     http://downloads.typesafe.com/releases/play-1.2.4.zip
    Extraction et ajout au PATH
    Création d'une nouvelle application :
          > play new demo-human-talks
    Préparation pour Eclipse :
          > play eclipsify
    Exécution :
          > play run
    Accès :
          http://localhost:9000/
           Principes, documentation local, API



    Play Framework 1.2.5 - http://www.playframework.com/ - Xavier NOPRE – 12/02/2013
Installation & démarrage




Play Framework 1.2.5 - http://www.playframework.com/ - Xavier NOPRE – 12/02/2013
Structure
    Répertoires :
        config/  fichiers de configuration
        app/
          models/  classes pour les modèles objet (mapping JPA)
          controllers/  classes pour les contrôleurs
          views/  fichier HTML de templating pour les vues

        test/  tests unitaires et tests fonctionnels
        public/  ressources statiques (images, CSS, Javascript)




    Play Framework 1.2.5 - http://www.playframework.com/ - Xavier NOPRE – 12/02/2013
Configuration
    Répertoire "conf":
        application.conf : configuration générale de l'application :
          Nom, mode (dev / prod), langs
          Serveur HTTP et sessions
          Logs
          Base de donnée : mémoire, fichier, MySQL, PostgreSQL, JDBC, …
          JPA, memcached, proxy, mail, …
        dependencies.yml
          Dépendances (artefacts type Maven ou Ivy)
        routes
          Routages : URL  controller.action
        messages
          Internationalisation i18n (multi-langue)



    Play Framework 1.2.5 - http://www.playframework.com/ - Xavier NOPRE – 12/02/2013
Configuration > dépendances
    Artefacts disponibles sur des repositories publiques :
            conf/dependencies.yml
            # Application dependencies

            require:
                - play
                - play -> crud
                - play -> secure
                - org.apache.commons -> commons-lang3 3.1
                - org.mockito -> mockito-all 1.9.5
                - org.easytesting -> fest-assert 1.4


    Mise à jour des dépendances :
          > play dependencies

    Play Framework 1.2.5 - http://www.playframework.com/ - Xavier NOPRE – 12/02/2013
Configuration > routage URLs
    Définitions des routages entre URL et actions des
     contrôleurs, et inversement
     conf/routes
     GET     /                                    Application.index
     GET     /public/                             staticDir:public
     *       /{controller}/{action}               {controller}.{action}
     # Backbone
     GET     /bb/projects                         BBProjects.getProjects
     GET     /bb/project/{id}                     BBProjects.getProject
     POST    /bb/project                          BBProjects.createProject
     PUT     /bb/project/{id}                     BBProjects.updateProject
     DELETE /bb/project/{id}                      BBProjects.deleteProject
     POST    /bb/project/public/{id}/{isPublic}   BBProjects.postPublicProject



    Utilisation dans une vue pour faire un lien :
          <a href="@{Clients.show(client.id)}">Show</a>


    Play Framework 1.2.5 - http://www.playframework.com/ - Xavier NOPRE – 12/02/2013
Models
    Play utilise Hibernate à travers JPA (Java Persistance Api)
    Les objets sont annotés @Entity et dérivent de Model
    Model fournit des méthodes utilitaires statiques :
        post.save(), post.delete(), Post.findAll(), Post.findById(5L),
         Post.find("byTitle", "My first post").fetch() …
                          @Entity
                          public class Post extends Model {

                              public String title;
                              public String content;
                              public Date postDate;

                              @ManyToOne
                              public Author author;

                              @OneToMany
                              public List<Comment> comments;
                          }

    Play Framework 1.2.5 - http://www.playframework.com/ - Xavier NOPRE – 12/02/2013
Controllers
    Traitent les requêtes
    Dérivent de play.mvc.Controller
    Méthodes statiques
    Récupération automatique des paramètres de requête
    Binding automatique de ces paramètres en objets, selon la
     signature de la méthode
        + Dates selon différents formats
        + Uploads POST "multipart/form-data" de fichiers  File
    Actions :
        Rendu : render(), renderJSON(), renderXML(), renderBinary()
        Autre : redirect() ou appel d'une autre méthode (chainage)

    Play Framework 1.2.5 - http://www.playframework.com/ - Xavier NOPRE – 12/02/2013
Controllers > Exemple
public class Clients extends Controller {

      public static void list() {
          List<Client> clients = Client.findAll();
          render(clients);                                app/views/Clients/list.html
      }

      public static void show(Long id) {
          Client client = Client.findById(id);
          renderTemplate("Clients/showClient.html", client);
      }                                         app/views/Clients/showClient.html
      public static void create(String name) {
          Client client = new Client(name);
          client.save();
          show(client.id);                                       chainage
      }
             public static void getUnreadMessages() {
}
                 List<Message> unreadMessages = MessagesBox.unreadMessages();
                 renderJSON(unreadMessages);
             }
    Play Framework 1.2.5 - http://www.playframework.com/ - Xavier NOPRE – 12/02/2013
Vues
    Templating Groovy
        Variable : ${client.name}
        Tags : #{script 'jquery.js' /} ou #{list items:clients, as:'client' }
            Tags personnalisés dans app/views/tags
        Actions : <a href="@{Clients.show(client.id)}">Show</a>
        Textes internationalisés : &{'clientName', client.name}
        Script Java : %{ fullName = "Name : "+client.getName(); }


    Système de "decorators" (= template parent, héritage)
        Tags #{extends 'main.html' /} et #{doLayout /}



    Play Framework 1.2.5 - http://www.playframework.com/ - Xavier NOPRE – 12/02/2013
Mais encore …
    Gestion d'ID pour différents déploiements (dev, test,…)
    Tests unitaires et fonctionnels
    Gestion de modules
        Personnels
        Public, grand nombre sur http://www.playframework.com/modules
        Notamment modules Secure, CRUD, …
    Déploiement
        En "natif" avec le moteur Play
        WAR déployé sur serveur d'application (Tomcat, …)
    Macro (tags) pour le templating des vues
    …
    Play Framework 1.2.5 - http://www.playframework.com/ - Xavier NOPRE – 12/02/2013
MERCI
    Xavier NOPRE :

        Développeur Java & Web

        Formation et accompagnement en ingénierie agile (tests unitaires,
         TDD, intégration continue, industrialisation Maven, etc…)
         et technos Java-WEB



            @xnopre                xnopre.blogspot.com


    Play Framework 1.2.5 - http://www.playframework.com/ - Xavier NOPRE – 12/02/2013

Contenu connexe

PDF
JSF2, Primefaces, Primefaces Mobile
PPTX
Présentation prime facesfinal
PDF
Spring Meetup Paris - Back to the basics of Spring (Boot)
PDF
Architecture java j2 ee a partager
PPTX
Les dessous du framework spring
PPT
Une (simple) présentation de Apache Maven 2
PDF
Apache Maven 3
JSF2, Primefaces, Primefaces Mobile
Présentation prime facesfinal
Spring Meetup Paris - Back to the basics of Spring (Boot)
Architecture java j2 ee a partager
Les dessous du framework spring
Une (simple) présentation de Apache Maven 2
Apache Maven 3

Tendances (20)

PPT
20081113 - Nantes Jug - Apache Maven
PDF
Concevoir, développer et sécuriser des micro-services avec Spring Boot
PPTX
Workshop Spring 3 - Tests et techniques avancées du conteneur Spring
PPTX
Presentation JEE et son écossystéme
PPT
GWT Principes & Techniques
PDF
JCertif 2012 : Maven par la pratique
PDF
ParisJUG Spring Boot
PDF
Jsf 110530152515-phpapp01
PPT
20090615 - Ch'ti JUG - Apache Maven
PDF
JBoss - chapitre JMX
PPT
Présentation Maven
PDF
Cours jee 1
PDF
Tp java ee.pptx
PPT
Les Servlets et JSP
PPTX
Sonar-Hodson-Maven
PPTX
Workshop Spring - Session 1 - L'offre Spring et les bases
PDF
Support JEE Servlet Jsp MVC M.Youssfi
PPTX
Workshop spring session 2 - La persistance au sein des applications Java
PDF
Gradle
PPTX
Introduction à spring boot
20081113 - Nantes Jug - Apache Maven
Concevoir, développer et sécuriser des micro-services avec Spring Boot
Workshop Spring 3 - Tests et techniques avancées du conteneur Spring
Presentation JEE et son écossystéme
GWT Principes & Techniques
JCertif 2012 : Maven par la pratique
ParisJUG Spring Boot
Jsf 110530152515-phpapp01
20090615 - Ch'ti JUG - Apache Maven
JBoss - chapitre JMX
Présentation Maven
Cours jee 1
Tp java ee.pptx
Les Servlets et JSP
Sonar-Hodson-Maven
Workshop Spring - Session 1 - L'offre Spring et les bases
Support JEE Servlet Jsp MVC M.Youssfi
Workshop spring session 2 - La persistance au sein des applications Java
Gradle
Introduction à spring boot
Publicité

En vedette (20)

PDF
Enib cours c.a.i. web - séance #5 : scala play! framework
PDF
Web application development using Play Framework (with Java)
PPTX
Play! Framework for JavaEE Developers
PDF
Using Play Framework 2 in production
PDF
Open Source Software and GitHub
PDF
Tp switch
PPTX
Gamification review 1
PPTX
PPTX
Frede space up paris 2013
PDF
Marquette Social Listening presentation
PPTX
User experience eBay
PPTX
807 103康八上 my comic book
PDF
อุปกรณ์เครือข่ายงคอมพิวเตอร์
PDF
Scala play-framework
PPT
Reclaiming the idea of the University
PDF
6º básico a semana 09 al 13 de mayo (1)
PDF
4º básico a semana 03 de junio al 10 de junio
PDF
Postavte zeď mezi svoje vývojáře
PDF
Recruit, Retain, Realize - How Third Party Transactional Data Can Power Your ...
PPTX
Giveandget.com
Enib cours c.a.i. web - séance #5 : scala play! framework
Web application development using Play Framework (with Java)
Play! Framework for JavaEE Developers
Using Play Framework 2 in production
Open Source Software and GitHub
Tp switch
Gamification review 1
Frede space up paris 2013
Marquette Social Listening presentation
User experience eBay
807 103康八上 my comic book
อุปกรณ์เครือข่ายงคอมพิวเตอร์
Scala play-framework
Reclaiming the idea of the University
6º básico a semana 09 al 13 de mayo (1)
4º básico a semana 03 de junio al 10 de junio
Postavte zeď mezi svoje vývojáře
Recruit, Retain, Realize - How Third Party Transactional Data Can Power Your ...
Giveandget.com
Publicité

Similaire à Play framework - Human Talks Grenoble - 12.02.2013 (20)

PDF
CHOUGDALI_CoursJEE.pdfhjkhjjjjjjjjjjjjjjjjjjjjjjjjjj
PPTX
Java dans Windows Azure, l'exemple de JOnAS
PDF
Rich Desktop Applications
PPTX
Java dans Windows Azure: l'exemple de Jonas
PPTX
HTML5 en projet
PDF
Présentation Gradle au LyonJUG par Grégory Boissinot - Zenika
KEY
La mobilité dans Drupal
PPTX
Comment réussir son projet en Angular 1.5 ?
PDF
Play Framework - Toulouse JUG - nov 2011
PDF
Presentation of GWT 2.4 (PDF version)
PPTX
Apache flink - prise en main rapide
PDF
Quelle place pour le framework Rails dans le développement d'application web
PDF
Backbonejs presentation
PDF
Gradle_LyonJUG
PPTX
Silverlight 4
PDF
Springioc
PPT
Soutenance Zend Framework vs Symfony
PPT
Aspect avec AspectJ
PPTX
Silverlight 3.MSDays EPITA 11/06/2009
PDF
iTunes Stats
CHOUGDALI_CoursJEE.pdfhjkhjjjjjjjjjjjjjjjjjjjjjjjjjj
Java dans Windows Azure, l'exemple de JOnAS
Rich Desktop Applications
Java dans Windows Azure: l'exemple de Jonas
HTML5 en projet
Présentation Gradle au LyonJUG par Grégory Boissinot - Zenika
La mobilité dans Drupal
Comment réussir son projet en Angular 1.5 ?
Play Framework - Toulouse JUG - nov 2011
Presentation of GWT 2.4 (PDF version)
Apache flink - prise en main rapide
Quelle place pour le framework Rails dans le développement d'application web
Backbonejs presentation
Gradle_LyonJUG
Silverlight 4
Springioc
Soutenance Zend Framework vs Symfony
Aspect avec AspectJ
Silverlight 3.MSDays EPITA 11/06/2009
iTunes Stats

Plus de Xavier NOPRE (6)

PDF
Human Talks Grenoble 08/09/2015 - AngularJS et Cordova = applications WEB et ...
PDF
Agilistes : n'oubliez pas la technique ! - Agile France - 23/05/2013
PDF
Jasmine : tests unitaires en JavaScript - Human Talks Grenoble 14.05.2013
PDF
Mix-IT 2013 - Agilistes : n'oubliez pas la technique - mix-it 2013
PPTX
Human Talks Grenoble - 11/12/2012 - TDD
PDF
Ingénierie agile : N&rsquo;oubliez pas vos développeurs
Human Talks Grenoble 08/09/2015 - AngularJS et Cordova = applications WEB et ...
Agilistes : n'oubliez pas la technique ! - Agile France - 23/05/2013
Jasmine : tests unitaires en JavaScript - Human Talks Grenoble 14.05.2013
Mix-IT 2013 - Agilistes : n'oubliez pas la technique - mix-it 2013
Human Talks Grenoble - 11/12/2012 - TDD
Ingénierie agile : N&rsquo;oubliez pas vos développeurs

Play framework - Human Talks Grenoble - 12.02.2013

  • 1. GRENOBLE Play framework (V1) : simplicité et productivité au service du développement WEB en Java Xavier NOPRE – 12/02/2013
  • 2. Préambule > Sondage  Développeur Java ?  Qui connait Play Framework ?  Qui utilise Play Framework ?  V1 ?  V2 ?  Précision … Play Framework 1.2.5 - http://www.playframework.com/ - Xavier NOPRE – 12/02/2013
  • 3. Introduction  Framework WEB complet  Pour des développeurs pour des développeurs  Pour une approche + simple et + rapide (vs JEE ou Spring)  Constitué de composants choisis (JPA, Hibernate, …)  Architecture Model View Controller  Rechargement à chaud en mode "dev"  Présentation des erreurs "serveur" dans la page HTML (explication et extrait de code)  Stateless & REST  Basé sur des conventions  Productivité ! Play Framework 1.2.5 - http://www.playframework.com/ - Xavier NOPRE – 12/02/2013
  • 4. Installation & démarrage  Téléchargement play-1.2.5.zip : http://downloads.typesafe.com/releases/play-1.2.4.zip  Extraction et ajout au PATH  Création d'une nouvelle application : > play new demo-human-talks  Préparation pour Eclipse : > play eclipsify  Exécution : > play run  Accès : http://localhost:9000/  Principes, documentation local, API Play Framework 1.2.5 - http://www.playframework.com/ - Xavier NOPRE – 12/02/2013
  • 5. Installation & démarrage Play Framework 1.2.5 - http://www.playframework.com/ - Xavier NOPRE – 12/02/2013
  • 6. Structure  Répertoires :  config/  fichiers de configuration  app/  models/  classes pour les modèles objet (mapping JPA)  controllers/  classes pour les contrôleurs  views/  fichier HTML de templating pour les vues  test/  tests unitaires et tests fonctionnels  public/  ressources statiques (images, CSS, Javascript) Play Framework 1.2.5 - http://www.playframework.com/ - Xavier NOPRE – 12/02/2013
  • 7. Configuration  Répertoire "conf":  application.conf : configuration générale de l'application :  Nom, mode (dev / prod), langs  Serveur HTTP et sessions  Logs  Base de donnée : mémoire, fichier, MySQL, PostgreSQL, JDBC, …  JPA, memcached, proxy, mail, …  dependencies.yml  Dépendances (artefacts type Maven ou Ivy)  routes  Routages : URL  controller.action  messages  Internationalisation i18n (multi-langue) Play Framework 1.2.5 - http://www.playframework.com/ - Xavier NOPRE – 12/02/2013
  • 8. Configuration > dépendances  Artefacts disponibles sur des repositories publiques : conf/dependencies.yml # Application dependencies require: - play - play -> crud - play -> secure - org.apache.commons -> commons-lang3 3.1 - org.mockito -> mockito-all 1.9.5 - org.easytesting -> fest-assert 1.4  Mise à jour des dépendances : > play dependencies Play Framework 1.2.5 - http://www.playframework.com/ - Xavier NOPRE – 12/02/2013
  • 9. Configuration > routage URLs  Définitions des routages entre URL et actions des contrôleurs, et inversement conf/routes GET / Application.index GET /public/ staticDir:public * /{controller}/{action} {controller}.{action} # Backbone GET /bb/projects BBProjects.getProjects GET /bb/project/{id} BBProjects.getProject POST /bb/project BBProjects.createProject PUT /bb/project/{id} BBProjects.updateProject DELETE /bb/project/{id} BBProjects.deleteProject POST /bb/project/public/{id}/{isPublic} BBProjects.postPublicProject  Utilisation dans une vue pour faire un lien : <a href="@{Clients.show(client.id)}">Show</a> Play Framework 1.2.5 - http://www.playframework.com/ - Xavier NOPRE – 12/02/2013
  • 10. Models  Play utilise Hibernate à travers JPA (Java Persistance Api)  Les objets sont annotés @Entity et dérivent de Model  Model fournit des méthodes utilitaires statiques :  post.save(), post.delete(), Post.findAll(), Post.findById(5L), Post.find("byTitle", "My first post").fetch() … @Entity public class Post extends Model { public String title; public String content; public Date postDate; @ManyToOne public Author author; @OneToMany public List<Comment> comments; } Play Framework 1.2.5 - http://www.playframework.com/ - Xavier NOPRE – 12/02/2013
  • 11. Controllers  Traitent les requêtes  Dérivent de play.mvc.Controller  Méthodes statiques  Récupération automatique des paramètres de requête  Binding automatique de ces paramètres en objets, selon la signature de la méthode  + Dates selon différents formats  + Uploads POST "multipart/form-data" de fichiers  File  Actions :  Rendu : render(), renderJSON(), renderXML(), renderBinary()  Autre : redirect() ou appel d'une autre méthode (chainage) Play Framework 1.2.5 - http://www.playframework.com/ - Xavier NOPRE – 12/02/2013
  • 12. Controllers > Exemple public class Clients extends Controller { public static void list() { List<Client> clients = Client.findAll(); render(clients);  app/views/Clients/list.html } public static void show(Long id) { Client client = Client.findById(id); renderTemplate("Clients/showClient.html", client); }  app/views/Clients/showClient.html public static void create(String name) { Client client = new Client(name); client.save(); show(client.id);  chainage } public static void getUnreadMessages() { } List<Message> unreadMessages = MessagesBox.unreadMessages(); renderJSON(unreadMessages); } Play Framework 1.2.5 - http://www.playframework.com/ - Xavier NOPRE – 12/02/2013
  • 13. Vues  Templating Groovy  Variable : ${client.name}  Tags : #{script 'jquery.js' /} ou #{list items:clients, as:'client' }  Tags personnalisés dans app/views/tags  Actions : <a href="@{Clients.show(client.id)}">Show</a>  Textes internationalisés : &{'clientName', client.name}  Script Java : %{ fullName = "Name : "+client.getName(); }  Système de "decorators" (= template parent, héritage)  Tags #{extends 'main.html' /} et #{doLayout /} Play Framework 1.2.5 - http://www.playframework.com/ - Xavier NOPRE – 12/02/2013
  • 14. Mais encore …  Gestion d'ID pour différents déploiements (dev, test,…)  Tests unitaires et fonctionnels  Gestion de modules  Personnels  Public, grand nombre sur http://www.playframework.com/modules  Notamment modules Secure, CRUD, …  Déploiement  En "natif" avec le moteur Play  WAR déployé sur serveur d'application (Tomcat, …)  Macro (tags) pour le templating des vues  … Play Framework 1.2.5 - http://www.playframework.com/ - Xavier NOPRE – 12/02/2013
  • 15. MERCI  Xavier NOPRE :  Développeur Java & Web  Formation et accompagnement en ingénierie agile (tests unitaires, TDD, intégration continue, industrialisation Maven, etc…) et technos Java-WEB @xnopre xnopre.blogspot.com Play Framework 1.2.5 - http://www.playframework.com/ - Xavier NOPRE – 12/02/2013