Book Image

Play Framework Cookbook

By : Alexander Reelsen
Book Image

Play Framework Cookbook

By: Alexander Reelsen

Overview of this book

<p>The Play framework is the new kid on the block of Java frameworks. By breaking with existing standards the play framework tries not to abstract away from HTTP as most web frameworks do, but tightly integrates with it. This means quite a shift for Java programmers. Understanding these concepts behind the play framework and its impact on web development with Java are crucial for fast development of applications.<br /><br />The Play Framework Cookbook starts where the beginner documentation ends. It shows you how to utilize advanced features of the Play framework &ndash; piece by piece and completely outlined with working applications!<br /><br />The reader will be taken through all layers of the Play Framework and provided with in-depth knowledge from as many examples and applications as possible. Leveraging the most from the Play framework means to think simple again in a java environment. Implement your own renderers, integrate tightly with HTTP, use existing code, improve site performance with caching and integrate with other web services and interfaces. Learn about non-functional issues like modularity or integration into production and testing environments. In order to provide the best learning experience during reading Play Framework Cookbook, almost every example is provided with source code, so you can start immediately to integrate recipes into your own play applications.</p>
Table of Contents (16 chapters)
Play Framework Cookbook
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Further Information About the Play Framework
Index

Using Google Chart API as a tag


Sooner or later, one of your clients will ask for graphical representation of something in your application. It may be time-based (revenue per day/month/year), or more arbitrary. Instead of checking available imaging libraries like JFreeChart, and wasting your own CPU cycles when creating images, you can rely on the Google Chart API that is available at http://code.google.com/apis/chart/.

This API supports many charts, some of which do not even resemble traditional graphs. We will come to this later in the recipe.

The source code of the example is available at examples/chapter4/mashup-chart-api.

How to do it...

Some random data to draw from might be useful. A customer entity and an order entity are created in the following code snippets:

public class Customer {

  public String name;
  public List<Order> orders = new ArrayList<Order>();
  
  public Customer() {
    name = RandomStringUtils.randomAlphabetic(10);
    for (int i = 0 ; i< 6 ; i++) {...