76
Play! Framework with Robin Warren

Play framework - Bristol Java meetup

Embed Size (px)

Citation preview

Page 1: Play framework - Bristol Java meetup

Play! Frameworkwith Robin Warren

Page 2: Play framework - Bristol Java meetup

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

Page 3: Play framework - Bristol Java meetup

What’s not in

1. A lot of Play 2

2. Funny jokes

Page 4: Play framework - Bristol Java meetup

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

Page 5: Play framework - Bristol Java meetup

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

Page 6: Play framework - Bristol Java meetup

Firstly...

How I came to the Play Framework

Page 7: Play framework - Bristol Java meetup

At Covalent Software until December last year

Page 8: Play framework - Bristol Java meetup

Covalent 3 years ago

Page 9: Play framework - Bristol Java meetup

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

Page 10: Play framework - Bristol Java meetup

The options

Page 11: Play framework - Bristol Java meetup

The criteria

1. Community

2. Used in production

3. MVC

4. Ease of development

5. Bonus - no XML, no GWT style

magic

Page 12: Play framework - Bristol Java meetup

The short list

Page 13: Play framework - Bristol Java meetup

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

Page 14: Play framework - Bristol Java meetup

How to Play!

Page 15: Play framework - Bristol Java meetup

Download

Page 16: Play framework - Bristol Java meetup

Extract

Page 17: Play framework - Bristol Java meetup

Create a project

Page 18: Play framework - Bristol Java meetup

Eclipsify (or netbeansify, or idealize) your project

Page 19: Play framework - Bristol Java meetup

Run your project

Page 20: Play framework - Bristol Java meetup

To the browser!

Page 21: Play framework - Bristol Java meetup

What have we got so far

Page 22: Play framework - Bristol Java meetup

app - MVC

Page 23: Play framework - Bristol Java meetup

configuration

Page 24: Play framework - Bristol Java meetup

application.conf

Page 25: Play framework - Bristol Java meetup

routes

Page 26: Play framework - Bristol Java meetup

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

Page 27: Play framework - Bristol Java meetup

Let’s make some changes

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

Page 28: Play framework - Bristol Java meetup

...The underpants gnomes

Page 29: Play framework - Bristol Java meetup

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

Page 30: Play framework - Bristol Java meetup

Model

Page 31: Play framework - Bristol Java meetup

Controller

Page 32: Play framework - Bristol Java meetup

View

Page 33: Play framework - Bristol Java meetup

main.html

Page 34: Play framework - Bristol Java meetup

The basics

1. Show list of known underpants locations

2. Ability to add underpants location

3. Ability to mark underpants as collected

Page 35: Play framework - Bristol Java meetup

Controller changes

Page 36: Play framework - Bristol Java meetup

View changes

Page 37: Play framework - Bristol Java meetup

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

Page 38: Play framework - Bristol Java meetup

Additions and refactoring

Page 39: Play framework - Bristol Java meetup

New controller

Page 40: Play framework - Bristol Java meetup

New view

Page 41: Play framework - Bristol Java meetup

Done!

The basics

1. Show list of known underpants locations

2. Ability to add underpants location

3. Ability to mark underpants as collected

Page 42: Play framework - Bristol Java meetup

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

Page 43: Play framework - Bristol Java meetup

Some useful additions

More stuff

1. Jobs

2. Controller inheritance and @Before methods

3. Tags

4. Testing

Page 44: Play framework - Bristol Java meetup

Some useful additions

More stuff

1. Jobs

2. Controller inheritance and @Before methods

3. Tags

4. Testing

Page 45: Play framework - Bristol Java meetup

Jobs

Used for

1. Background tasks

2. Doing work asynchronously in controllers

Page 46: Play framework - Bristol Java meetup

Background tasks

Page 47: Play framework - Bristol Java meetup

Asynchronous work in controllers

Page 48: Play framework - Bristol Java meetup

Controller inheritance and @Before methods

Page 49: Play framework - Bristol Java meetup

Tags

Tags can be

● Templates (html, js, whatevs)

● Java FastTag subclass

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

Page 50: Play framework - Bristol Java meetup

Tags

Page 51: Play framework - Bristol Java meetup

Tags

Page 52: Play framework - Bristol Java meetup

Some useful additions

More stuff

1. Jobs

2. Controller inheritance and @Before methods

3. Tags

4. Testing

Page 53: Play framework - Bristol Java meetup

Testing

Page 54: Play framework - Bristol Java meetup

Unit test

Page 55: Play framework - Bristol Java meetup

Functional test

Page 56: Play framework - Bristol Java meetup

Selenium test

Page 57: Play framework - Bristol Java meetup

Test data

Page 58: Play framework - Bristol Java meetup

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

Page 59: Play framework - Bristol Java meetup

Even more useful additions

A more stuff (in less detail)

1. Validation

2. Built in tags and Java extensions

3. Modules

Page 60: Play framework - Bristol Java meetup

Adding some validation

Page 61: Play framework - Bristol Java meetup

Built in tags and extensions

Page 62: Play framework - Bristol Java meetup

Modules

Page 63: Play framework - Bristol Java meetup

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

Page 64: Play framework - Bristol Java meetup

Larger apps with Play

Some thoughts...

Page 65: Play framework - Bristol Java meetup

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

Page 66: Play framework - Bristol Java meetup

Decompose Controllers early

Page 67: Play framework - Bristol Java meetup

Decompose Controllers early

Page 68: Play framework - Bristol Java meetup

No catch all routes

Page 69: Play framework - Bristol Java meetup

Split app up into modules

Page 70: Play framework - Bristol Java meetup

Don’t use their selenium tag or headless browser

Page 71: Play framework - Bristol Java meetup

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

Page 72: Play framework - Bristol Java meetup

Play 2 vs Play 1

Page 73: Play framework - Bristol Java meetup
Page 74: Play framework - Bristol Java meetup

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.

Page 75: Play framework - Bristol Java meetup

fin

Page 76: Play framework - Bristol Java meetup

fintwitter: @robinwarren

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