Skip to content

aogriffiths/play2.0-form-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Forms Using Play 2.0

Prerequisites

You will need to know a little java and how play 2.0 works. You will need play 2.0 and git installed to run this example from your own machine.

To run it, simply do a "git clone", cd to the project directory, then "play run".

The Code

The first thing to say is this app is not made to look good! The UI is simple and dull. The real purpose is to demostrate the code, which is well commented. Below is a quick overview of how it hangs together and you can click the links to read the comments inline with the code to find out more.

The function of the app is to provided CRUD opperations for a model object called "Thing"

Start by looking at Application.java.

There are three write operations. These correspond to the POST requests.

  • thingCreate() - Create a new Thing
  • thingUpdate(id) - Update an existing Thing
  • thingDelete(id) - Delete an existing Thing

There are four read operations. These correspond to the GET requests.

  • thingList() - GET a list of all Things for viewing
  • thingView(id) - GET a single Thing for viewing
  • thingEdit(id) - GET a single Thing for editing - POSTS to thingUpdate(id)
  • thingNew(id) - GET a new Thing for creating - POSTS to thingCreate()

The list, single and edit views can all POST to thingDelete(id)

All of these java methods have http methods routed to them as per routes (four are GET methods and one is a POST method).

The views are all in the standard app/views package and correspond to the List, Edit, New and View methods.

List

The most simple case. Application.thingList() finds all the things in the dabase and sends them to the thingList.scala.html template to be renderd.

Create

Application.thingNew() creates an empty Form for creating a new Thing. thingNew.scala.html renders the form.

View

Another simple one. Application.thingView(id) simply finds the Thing by id and sends it to thingView.scala.html to be rendered.

Edit

Similarities to both View and Create. Application.thingEdit(id) finds the Thing by id and creates an edit form from it. The Thing and the Form are sent to thingEdit.scala.html to be rendered.

List of Examples

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published