2. What is Play? A clean alternative to the bloated Java Enterprise Edition Pure Java framework – allows you to keep your preferred development tools and libraries Focuses on developer productivity and targets RESTful(Representational State Transfer) architectures Consist of clients and servers Clients initiate requests to servers Servers process requests and return appropriate responses Requests and responses are built around the transfer of representations of resources
3. The foundation of Play MVC architecture You’ve got a database on one side and a web browser on the other. Classes are models, the application is the controller, generated HTML is the view HTTP-to-code mapping Example: binding URI patterns to Java procedure calls Efficient template engine The expression language used is Groovy Templating system mainly used to render HTML responses
4. Why is play awesome? Fix the bug and hit reload The framework compiles your Java sources directly and hot-reloads them into the JVM without the need to restart the server You can then edit, reload and see your modifications immediately, just as in a Rails environment Whenever an error occurs, the framework identifies and shows you the problem Stack traces are stripped down and optimized to make it easier to solve problems Java Persistence API (JPA) and The Java Persistence Query Language (JPQL) A persistence entity is a lightweight Java class saved to a table in a relational database.
5. JPA, JPQL // Java Persistence API example @Entity public class Book { @Id private Integer id; private String title; private String isbn; @ManyToOne private Publisher publisher; @ManyToMany private List<Author> authors; }
6. JPA, JPQL // Java Persistence Query Language example public void messages(intpage, User connectedUser) { List<Message> messages = Message.find(“ user = ? and read = false order by date desc", connectedUser).from(page * 10).fetch(10); render(connectedUser, messages); }
7. Why is play awesome? Test-driven development Run them directly in a browser using Selenium Selenium is a Firefox add-on that records clicks, typing, and other actions Database support through JDBC Object-relational mapping using Hibernate (with the JPA API) Integrated cache support Straightforward web services consumption either in JSON or XML OpenIDsupport for distributed authentication Ready to be deployed anywhere (application server, Google App Engine, Cloud, etc…) Image manipulation API.
9. Things you can do with play Bind an HTTP parameter to a Java method parameter // a simple request /articles/archive?date=08/01/08&page=2 // the Java method public staticvoid archive(Date date, Integer page) { List<Article> articles = Articles.fromArchive(date, page); render(articles); }
10. Things you can do with play Smart binding with any class // a simple model public class Person { public String name; public Integer age; } // a simple controller public static void add(Person p) { p.save(); } // a simple HTML form <form action="add" method="POST"> Name: <input type="text" name="p.name" /> Age: <input type="text" name="p.age" /> </form>
11. Things you can do with play Redirect to an action by calling the corresponding Java method // a simple model with a procedure public static void show(Long id) { Article article = Article.findById(id); render(article); } // use the equivalent syntax: <a href="@{Article.show(article.id)}"> ${article.title} </a>
12. Things you can do with play Redirect to an action by calling the corresponding Java method (another example) // a simple model with a procedure public static void edit(Long id, String title) { Article article = Article.findById(id); article.title= title; article.save(); show(id); } // generated HTML: <a href="/articles/15"> My new article </a>
13. Things you can do with play Straightforward file upload management // the Java code public static void uploadPhoto(String title, File photo) { ... } // a simple HTML form <form action="@{Article.uploadPhoto()}" method="POST" enctype="multipart/form-data"> <input type="text" name="title" /> <input type="file" id="photo" name="photo" /> <input type="submit" value="Send it..." /> </form>