SlideShare a Scribd company logo
Play framework workshop
January 2014, Tel Aviv
Agenda
•

Session One: play for web developers (java)
•
•

Templates, URL mapping, reverse mapping

•

Forms, validation

•

RIA, REST, async responses (node.js style)

•
•

Play web application structure

WebSocket

Session Two: play beyond web app (scala)
•

Compossible futures

•

Iteratee with friends (Enumerator and Enumeratee)

•

Akka actors

•

Akka dataflow
Setup
•

git clone https://github.com/skibaa/play-meetup-jan14

•

cd play-meetup-jan14/youtube-play-java

•

play (or play debug)

•

eclipse or idea

•

run

•

http://localhost:9000
Day one workshop steps
1. Replace the generic app home page with ours (hands-on)
2. Add Twitter Bootstrap, upgrade query
3. Add /player action and view (hands-on)
4. Add /remote action, view and HTML form
5. RIA, javascript routes
6. Implement YouTube search, make HTML dynamic with Angular.js
7. Show search results properly (hands-on)
8. ‘Play video’ server side place holder (hands-on)
9. WebSocket
10.Implement ‘Play video’ server side (hands-on)
Step 1 (hands-on)
•

Change index.scala.html and/or main.scala.html, save,
refresh browser

•

Make errors in Application.java, routes,
index.scala.html - see the error reporting facilities of
Play

•

Play with view parameters (add a new one, show it in
HTML)

•

Run tests, fix them by editing ApplicationTest.java and
IntegrationTest.java
Checkout step1 complete
•

see your changes
•
•

•

git status
git diff | view -

clean work dir
•

git stash #put your changes aside, apply them later with git stash apply

•

git commit -m “any commit message” #will need to merge

•

git checkout -- . #DANGER: removes all your changes

•

option - create a local branch: git checkout -b step1

•

go to step1 complete: git pull origin step1

•

option - checkout to a separate dir: git clone -b step1 http://github.com/skibaa/play-meetupjan14.git step1
Step 2

•

Open http://getbootstrap.com/css/

•

Find the documentation for img-rounded, col-lg-5, btn

•

Change col-lg-5 to col-lg-4, see the effect

•

Play with styles as you wish
Step 3 (hands-on)
•

Add a ‘player’ action to Application.java, similar to ‘index’

•

Add a URL mapping to routes

•

Add an ‘onClick’ event to Player button in HTML, opening /player in a new
browser window

•

Create a new view player.scala.html, copy content from https://
developers.google.com/youtube/iframe_api_reference#Getting%20started

•

Generate a random int in the ‘player’ action, and show it in the view at the
top

•

After hands-on: how to pass more sections to the main template (in
addition to @contents)
Step 4
•

HTML forms in Play - MVC + validation + error
reporting

•

Model - PlayerConnect.java

•

Controller - create, bind, check errors

•

View - show form, show errors
Step 5
•

What is a single page application?

•

REST controllers in Play, producing JSON

•

javascript routes - why?

•

javascript routes - how?

•

Documentation: missing for Java, use Zentask
documentation http://www.playframework.com/
documentation/2.2.x/JavaGuide6
Step 6
•

YouTupe search API: https://developers.google.com/
youtube/v3/docs/search/list#try-it

•

Mandatory parameter ‘part’. We will use ‘part=snippet’

•

Search parameter ‘q’

•

API key parameter ‘key’

•

Read https://developers.google.com/places/documentation/

•

Get your own key at https://cloud.google.com/console/
project
Step 6 cont.
•

AngularJS - why?

•

MVC in a single page application

•

<p>1 + 2 = {{ 1 + 2 }}</p>

•

$scope

•

Two-way binding

•

http://docs.angularjs.org/tutorial/step_02: ng-repeat
Step 7 (hands-on)
•

Run queries on https://developers.google.com/
youtube/v3/docs/search/list#try-it

•

Look at the result JSON

•

Remove searchResults.push from controllers.js,
substitute results with the real ones

•

Correct remoteSearch.scala.html to loop on results in
the format, created by controllers.js
Step 8 (hands-on)
•

Create a new action ‘playVideo’ in Application.java

•

Add it to routes and to javascript routes

•

Add a videoId and thumbnailUrl parameters to playVideo

•

add onPlay in controllers.js and ng-click=‘onPlay(…)’ with videoId
and thumbnail

•

Make AJAX call from onPlay to playVideo on server side.

•

Return from the server side JSON, including thumbnailUrl

•

Display “Video is playing” with thumbnail of current video
Step 9
•

WebSocket - don’t call us, we’ll call you

•

Player passively waits for the videoId to be sent from
server

•

onMessage: make player.loadVideoById call, provided
by YouTube API

•

Server-side: looks similar (onReady, onMessage,
onClose)
Step 10 (hands-on)
•

Add playerId parameter to the Application.playVideo

•

Do not forget to add playerId also in routes,
remoteSearch.scala.html, controllers.js ;)

•

Find PlayerInfo by playerId

•

call playerInfo.outSocket.write with JSON containing videoId

•

only if that succeeds, return JSON with status “playing”

•

Bonus question: why there are exceptions on the server
console? (hint: “WS is open” starts with “W”)
Thank you and let’s stay in
touch!

•

andrew@tikalk.com

•

http://tikalk.com/java

•

https://www.facebook.com/TikalKnowledge

More Related Content

PDF
Web application development using Play Framework (with Java)
PPTX
Play! Framework for JavaEE Developers
PPT
Introduction to Play Framework
PDF
Play framework
PDF
Play framework 2 : Peter Hilton
PDF
Using Play Framework 2 in production
PDF
Play Framework: The Basics
PPTX
Angular beans
Web application development using Play Framework (with Java)
Play! Framework for JavaEE Developers
Introduction to Play Framework
Play framework
Play framework 2 : Peter Hilton
Using Play Framework 2 in production
Play Framework: The Basics
Angular beans

What's hot (20)

PDF
Developing Modern Java Web Applications with Java EE 7 and AngularJS
PDF
Scala and Play with Gradle
PDF
Play Framework 2.5
ODP
CodeIgniter PHP MVC Framework
PDF
Choosing a Javascript Framework
PDF
Kandroid for nhn_deview_20131013_v5_final
PDF
Play vs Grails Smackdown - Devoxx France 2013
PDF
High Performance JavaScript - jQuery Conference SF Bay Area 2010
PPTX
Faster Java EE Builds with Gradle
PPTX
Managed Beans: When, Why and How
PDF
Apache DeltaSpike the CDI toolbox
PDF
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
PDF
Java(ee) mongo db applications in the cloud
PDF
Play Framework on Google App Engine - Productivity Stack
PDF
Connect2017 DEV-1550 Why Java 8? Or, What's a Lambda?
PPT
Build Your Own CMS with Apache Sling
PPTX
Enough with the JavaScript already!
PDF
Apache Lucene for Java EE Developers
PDF
Modular Test-driven SPAs with Spring and AngularJS
PDF
Using React with Grails 3
Developing Modern Java Web Applications with Java EE 7 and AngularJS
Scala and Play with Gradle
Play Framework 2.5
CodeIgniter PHP MVC Framework
Choosing a Javascript Framework
Kandroid for nhn_deview_20131013_v5_final
Play vs Grails Smackdown - Devoxx France 2013
High Performance JavaScript - jQuery Conference SF Bay Area 2010
Faster Java EE Builds with Gradle
Managed Beans: When, Why and How
Apache DeltaSpike the CDI toolbox
Red Hat and Oracle: Delivering on the Promise of Interoperability in Java EE 7
Java(ee) mongo db applications in the cloud
Play Framework on Google App Engine - Productivity Stack
Connect2017 DEV-1550 Why Java 8? Or, What's a Lambda?
Build Your Own CMS with Apache Sling
Enough with the JavaScript already!
Apache Lucene for Java EE Developers
Modular Test-driven SPAs with Spring and AngularJS
Using React with Grails 3
Ad

Viewers also liked (8)

PDF
Play framework: lessons learned
PDF
TCE introduction (scalability with Scala and Akka)
PDF
From Second Screen Social App to Continuous Multi-Screen Experience
PPTX
Vaadin7 coding ui components
PDF
Simple Open Source Java Cloud App Stack with Guice, Hibernate, Jersey and Vaadin
PDF
Scala, Play Framework и SBT для быстрого прототипирования и разработки веб-пр...
PPTX
Osgi based cloud system architecture - Open Cloud Engine
KEY
Enterprise Java Web Application Frameworks Sample Stack Implementation
Play framework: lessons learned
TCE introduction (scalability with Scala and Akka)
From Second Screen Social App to Continuous Multi-Screen Experience
Vaadin7 coding ui components
Simple Open Source Java Cloud App Stack with Guice, Hibernate, Jersey and Vaadin
Scala, Play Framework и SBT для быстрого прототипирования и разработки веб-пр...
Osgi based cloud system architecture - Open Cloud Engine
Enterprise Java Web Application Frameworks Sample Stack Implementation
Ad

Similar to Play Framework workshop: full stack java web app (20)

PPTX
Silicon Valley Code Camp 2011: Play! as you REST
ODP
eXo Platform SEA - Play Framework Introduction
PPT
Hands on web development with play 2.0
PDF
Play Framework Introduction
PDF
Play framework productivity formula
PPT
Intoduction to Play Framework
PDF
Introduction in the play framework
PPTX
How to Play at Work - A Play Framework Tutorial
PDF
An Introduction to Play 2 Framework
KEY
Play Support in Cloud Foundry
PDF
Play Framework
PPTX
Developing web apps using Java and the Play framework
PDF
Node.js vs Play Framework
PDF
Play 2 Java Framework with TDD
PDF
PDF
Play 23x Documentation For Scala Developers 23x Unknown
PPTX
Play framework - Bristol Java meetup
PDF
Having Fun with Play
PDF
Modern Web Framework : Play framework
PDF
Your First Scala Web Application using Play 2.1
Silicon Valley Code Camp 2011: Play! as you REST
eXo Platform SEA - Play Framework Introduction
Hands on web development with play 2.0
Play Framework Introduction
Play framework productivity formula
Intoduction to Play Framework
Introduction in the play framework
How to Play at Work - A Play Framework Tutorial
An Introduction to Play 2 Framework
Play Support in Cloud Foundry
Play Framework
Developing web apps using Java and the Play framework
Node.js vs Play Framework
Play 2 Java Framework with TDD
Play 23x Documentation For Scala Developers 23x Unknown
Play framework - Bristol Java meetup
Having Fun with Play
Modern Web Framework : Play framework
Your First Scala Web Application using Play 2.1

Recently uploaded (20)

PPTX
sap open course for s4hana steps from ECC to s4
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Machine learning based COVID-19 study performance prediction
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
Programs and apps: productivity, graphics, security and other tools
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Cloud computing and distributed systems.
PPT
Teaching material agriculture food technology
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Empathic Computing: Creating Shared Understanding
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
sap open course for s4hana steps from ECC to s4
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Unlocking AI with Model Context Protocol (MCP)
Review of recent advances in non-invasive hemoglobin estimation
Machine learning based COVID-19 study performance prediction
Reach Out and Touch Someone: Haptics and Empathic Computing
20250228 LYD VKU AI Blended-Learning.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
MIND Revenue Release Quarter 2 2025 Press Release
Programs and apps: productivity, graphics, security and other tools
The AUB Centre for AI in Media Proposal.docx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Cloud computing and distributed systems.
Teaching material agriculture food technology
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
NewMind AI Weekly Chronicles - August'25-Week II
Empathic Computing: Creating Shared Understanding
Assigned Numbers - 2025 - Bluetooth® Document
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf

Play Framework workshop: full stack java web app

  • 2. Agenda • Session One: play for web developers (java) • • Templates, URL mapping, reverse mapping • Forms, validation • RIA, REST, async responses (node.js style) • • Play web application structure WebSocket Session Two: play beyond web app (scala) • Compossible futures • Iteratee with friends (Enumerator and Enumeratee) • Akka actors • Akka dataflow
  • 3. Setup • git clone https://github.com/skibaa/play-meetup-jan14 • cd play-meetup-jan14/youtube-play-java • play (or play debug) • eclipse or idea • run • http://localhost:9000
  • 4. Day one workshop steps 1. Replace the generic app home page with ours (hands-on) 2. Add Twitter Bootstrap, upgrade query 3. Add /player action and view (hands-on) 4. Add /remote action, view and HTML form 5. RIA, javascript routes 6. Implement YouTube search, make HTML dynamic with Angular.js 7. Show search results properly (hands-on) 8. ‘Play video’ server side place holder (hands-on) 9. WebSocket 10.Implement ‘Play video’ server side (hands-on)
  • 5. Step 1 (hands-on) • Change index.scala.html and/or main.scala.html, save, refresh browser • Make errors in Application.java, routes, index.scala.html - see the error reporting facilities of Play • Play with view parameters (add a new one, show it in HTML) • Run tests, fix them by editing ApplicationTest.java and IntegrationTest.java
  • 6. Checkout step1 complete • see your changes • • • git status git diff | view - clean work dir • git stash #put your changes aside, apply them later with git stash apply • git commit -m “any commit message” #will need to merge • git checkout -- . #DANGER: removes all your changes • option - create a local branch: git checkout -b step1 • go to step1 complete: git pull origin step1 • option - checkout to a separate dir: git clone -b step1 http://github.com/skibaa/play-meetupjan14.git step1
  • 7. Step 2 • Open http://getbootstrap.com/css/ • Find the documentation for img-rounded, col-lg-5, btn • Change col-lg-5 to col-lg-4, see the effect • Play with styles as you wish
  • 8. Step 3 (hands-on) • Add a ‘player’ action to Application.java, similar to ‘index’ • Add a URL mapping to routes • Add an ‘onClick’ event to Player button in HTML, opening /player in a new browser window • Create a new view player.scala.html, copy content from https:// developers.google.com/youtube/iframe_api_reference#Getting%20started • Generate a random int in the ‘player’ action, and show it in the view at the top • After hands-on: how to pass more sections to the main template (in addition to @contents)
  • 9. Step 4 • HTML forms in Play - MVC + validation + error reporting • Model - PlayerConnect.java • Controller - create, bind, check errors • View - show form, show errors
  • 10. Step 5 • What is a single page application? • REST controllers in Play, producing JSON • javascript routes - why? • javascript routes - how? • Documentation: missing for Java, use Zentask documentation http://www.playframework.com/ documentation/2.2.x/JavaGuide6
  • 11. Step 6 • YouTupe search API: https://developers.google.com/ youtube/v3/docs/search/list#try-it • Mandatory parameter ‘part’. We will use ‘part=snippet’ • Search parameter ‘q’ • API key parameter ‘key’ • Read https://developers.google.com/places/documentation/ • Get your own key at https://cloud.google.com/console/ project
  • 12. Step 6 cont. • AngularJS - why? • MVC in a single page application • <p>1 + 2 = {{ 1 + 2 }}</p> • $scope • Two-way binding • http://docs.angularjs.org/tutorial/step_02: ng-repeat
  • 13. Step 7 (hands-on) • Run queries on https://developers.google.com/ youtube/v3/docs/search/list#try-it • Look at the result JSON • Remove searchResults.push from controllers.js, substitute results with the real ones • Correct remoteSearch.scala.html to loop on results in the format, created by controllers.js
  • 14. Step 8 (hands-on) • Create a new action ‘playVideo’ in Application.java • Add it to routes and to javascript routes • Add a videoId and thumbnailUrl parameters to playVideo • add onPlay in controllers.js and ng-click=‘onPlay(…)’ with videoId and thumbnail • Make AJAX call from onPlay to playVideo on server side. • Return from the server side JSON, including thumbnailUrl • Display “Video is playing” with thumbnail of current video
  • 15. Step 9 • WebSocket - don’t call us, we’ll call you • Player passively waits for the videoId to be sent from server • onMessage: make player.loadVideoById call, provided by YouTube API • Server-side: looks similar (onReady, onMessage, onClose)
  • 16. Step 10 (hands-on) • Add playerId parameter to the Application.playVideo • Do not forget to add playerId also in routes, remoteSearch.scala.html, controllers.js ;) • Find PlayerInfo by playerId • call playerInfo.outSocket.write with JSON containing videoId • only if that succeeds, return JSON with status “playing” • Bonus question: why there are exceptions on the server console? (hint: “WS is open” starts with “W”)
  • 17. Thank you and let’s stay in touch! • [email protected] • http://tikalk.com/java • https://www.facebook.com/TikalKnowledge