Play framework - Bristol Java meetup

Preview:

Citation preview

Play! Frameworkwith Robin Warren

What’s in this presentation

1. Why you may want to use the Play!

Framework

2. Overview of building a small app

3. Some other bits and bobs

What’s not in

1. A lot of Play 2

2. Funny jokes

Coming up

● How I came to Play!

● Getting started

● Building our first app

● More stuff

● A bit more stuff (in less detail)

● Building larger apps in Play!

● Play 2 vs Play 1

Coming up

● How I came to Play!

● Getting started

● Building our first app

● More stuff

● A bit more stuff (in less detail)

● Building larger apps in Play!

● Play 2 vs Play 1

Firstly...

How I came to the Play Framework

At Covalent Software until December last year

Covalent 3 years ago

How I came to Play!

● Large existing code base

● Development team of 15

● Existing active user base

● Time pressure (as always)

● + Opportunity to adopt some better tech

The options

The criteria

1. Community

2. Used in production

3. MVC

4. Ease of development

5. Bonus - no XML, no GWT style

magic

The short list

Coming up

● How I came to Play!

● Getting started

● Building our first app

● More stuff

● A bit more stuff (in less detail)

● Building larger apps in Play!

● Play 2 vs Play 1

How to Play!

Download

Extract

Create a project

Eclipsify (or netbeansify, or idealize) your project

Run your project

To the browser!

What have we got so far

app - MVC

configuration

application.conf

routes

Coming up

● How I came to Play!

● Getting started

● Building our first app

● More stuff

● A bit more stuff (in less detail)

● Building larger apps in Play!

● Play 2 vs Play 1

Let’s make some changes

We will build a tool to help our new clients...

...The underpants gnomes

A detailed spec

The basics

1. Show list of known underpants locations

2. Ability to add underpants location

3. Ability to mark underpants as collected

Model

Controller

View

main.html

The basics

1. Show list of known underpants locations

2. Ability to add underpants location

3. Ability to mark underpants as collected

Controller changes

View changes

Nearly done for v1

The basics

1. Show list of known underpants locations

2. Ability to add underpants location

3. Ability to mark underpants as collected

Additions and refactoring

New controller

New view

Done!

The basics

1. Show list of known underpants locations

2. Ability to add underpants location

3. Ability to mark underpants as collected

Coming up

● How I came to Play!

● Getting started

● Building our first app

● More stuff

● A bit more stuff (in less detail)

● Building larger apps in Play!

● Play 2 vs Play 1

Some useful additions

More stuff

1. Jobs

2. Controller inheritance and @Before methods

3. Tags

4. Testing

Some useful additions

More stuff

1. Jobs

2. Controller inheritance and @Before methods

3. Tags

4. Testing

Jobs

Used for

1. Background tasks

2. Doing work asynchronously in controllers

Background tasks

Asynchronous work in controllers

Controller inheritance and @Before methods

Tags

Tags can be

● Templates (html, js, whatevs)

● Java FastTag subclass

Let’s create a profitable tag for the main view...

Tags

Tags

Some useful additions

More stuff

1. Jobs

2. Controller inheritance and @Before methods

3. Tags

4. Testing

Testing

Unit test

Functional test

Selenium test

Test data

Coming up

● How I came to Play!

● Getting started

● Building our first app

● More stuff

● A bit more stuff (in less detail)

● Building larger apps in Play!

● Play 2 vs Play 1

Even more useful additions

A more stuff (in less detail)

1. Validation

2. Built in tags and Java extensions

3. Modules

Adding some validation

Built in tags and extensions

Modules

Coming up

● How I came to Play!

● Getting started

● Building our first app

● More stuff

● A bit more stuff (in less detail)

● Building larger apps in Play!

● Play 2 vs Play 1

Larger apps with Play

Some thoughts...

Larger apps with Play!

1. Decompose controllers early

2. No catch all routes (remove magic)

3. Split app up into modules

4. Don’t use their selenium tag (unless you know

better?) or the headless browser

Decompose Controllers early

Decompose Controllers early

No catch all routes

Split app up into modules

Don’t use their selenium tag or headless browser

Coming up

● How I came to Play!

● Getting started

● Building our first app

● More stuff

● A bit more stuff (in less detail)

● Building larger apps in Play!

● Play 2 vs Play 1

Play 2 vs Play 1

Most relevant for developers

1. Templates: Scala (from Groovy)

2. Less magic (aka bytecode generation etc.)

3. EBean instead of hibernate

4. bindFromRequest()

5. Asset directory - makes it easy to work with

coffeescript etc.

fin

fintwitter: @robinwarren

linkedIn: https://www.linkedin.com/in/robinwarren

Recommended