Developing web apps using Java and the Play framework
Upcoming SlideShare
Loading in...5
×
 

Developing web apps using Java and the Play framework

on

  • 3,895 views

 

Statistics

Views

Total Views
3,895
Views on SlideShare
3,886
Embed Views
9

Actions

Likes
3
Downloads
89
Comments
0

3 Embeds 9

http://www.linkedin.com 5
http://twitter.com 3
http://paper.li 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Developing web apps using Java and the Play framework Developing web apps using Java and the Play framework Presentation Transcript

  • developing web applications using Java and the Play framework
  • 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
  • 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
  • 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.
  • 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;
    }
  • 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);
    }
  • 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.
  • Things you can do with play
  • 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);
    }
  • 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>
  • 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>
  • 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>
  • 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>
  • DEMO
    Let’s create our own web application:
    a personal agenda
  • Questions?