Outils pour utilisateurs

Outils du site


informatique:java:frameworks:play_framework

Play! framework

The High Velocity Web Framework For Java and Scala : www.playframework.org

C'est le Symfony (Php) de Java ! Ce framework n'est pas basé sur J2EE, il embarque directement sont serveur (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 Akka, Play provides predictable and minimal resource comsumption (CPU, memory, threads) for highly-scalable applications.

Play! utilise les frameworks

    • 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
  • Akka pour son fonctionnement asynchrone.
  • Ebean a Java ORM

Hébergement sur le web

Community

doc

Présentations:

Tutoriels:

Autres:

Encore:

Livres:

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:

Map update:

Forms

  • 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<String, String[]> 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)));
  }
 
}
informatique/java/frameworks/play_framework.txt · Dernière modification : 05/11/2016 13:37 de cyrille

Sauf mention contraire, le contenu de ce wiki est placé sous les termes de la licence suivante : CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki