Abdul Habra's Blog
Build CRUD Apps With Play Framework

Introduction

Play (playframework.org) is a Java framework that makes it very easy to build web applications. Here I show how to build a CRUD web app in a way that reminds me of RoR or Grails. You only need to know Java to follow this example. Play’s website contains excellent documentation and I will not repeat them here.

Some of the material here was presented at CoJug on 2010.06.08. The CoJug presentation contained more than what is provided here, and was presented by Nilanjan Raychaudhuri and myself.

Setup

  1. Java 1.5 or higher installed.
  2. Play installed, remember to add Play’s location to the path.
  3. Eclipse 3.5 installed. (This is a personal choice, you may use any IDE or text editor).

This will be a simple CRUD application which manages the following entities:

  1. A group of companies.
  2. Each Company can have 0 or more Department.
  3. Each Department can have 0 or more Employee.

Create App’s Skeleton

  1. From the command line, navigate to the directory which will contain the new application.
  2. Run this command: play new corporations
  3. You will be prompted to enter the application’s name, enter Corporations
  4. The above will create an empty Play application in the corporations directory.
  5. To try what you created, run this command:

      cd corporations
     
    play run
  6. In your web browser, go to http://localhost:9000/
  7. You should get a page titled “Your application is ready !”
  8. This proves that Play is running and that you application has started.

Read More