List of Listings

Chapter 1. Introduction to Play 2

Listing 1.1. Command-line output when you create a new Play application

Listing 1.2. Command-line output when you run the application

Listing 1.3. Files in a new Play application

Chapter 2. Your first Play application

Listing 2.1. Override Twitter Bootstrap—public/stylesheets/main.css

Listing 2.2. conf/messages

Listing 2.3. conf/messages.es

Listing 2.4. conf/messages.fr

Listing 2.5. conf/messages.nl

Listing 2.6. The model—app/models/Product.scala

Listing 2.7. The list page template—app/views/products/list.scala.html

Listing 2.8. The layout template—app/views/main.scala.html

Listing 2.9. The products controller—app/controllers/Products.scala

Listing 2.10. Routes configuration file—conf/routes

Listing 2.11. The default controller—app/controllers/Application.scala

Listing 2.12. Debug information template—app/views/debug.scala.html

Listing 2.13. Page footer to the layout template—app/views/main.scala.html

Listing 2.14. Product-details—app/views/products/details.scala.html

Listing 2.15. The bar code tag—app/views/tags/barcode.scala.html

Listing 2.16. Additional details page messages—conf/messages

Listing 2.17. Additional details page messages—conf/messages.es

Listing 2.18. Additional details page messages—conf/messages.fr

Listing 2.19. Additional details page messages—conf/messages.nl

Listing 2.20. Details page controller action—app/controllers/Products.scala

Listing 2.21. Details page route—conf/routes

Listing 2.22. Barcodes controller—app/controllers/Barcodes.scala

Listing 2.23. conf/messages

Listing 2.24. conf/messages.es

Listing 2.25. conf/messages.fr

Listing 2.26. conf/messages.nl

Listing 2.27. Product form—app/controllers/Products.scala

Listing 2.28. New main template—app/views/main.scala.html

Listing 2.29. Add product button—app/views/products/list.scala.html

Listing 2.30. New-product—app/views/products/editProduct.scala.html

Listing 2.31. Save a new product—app/models/Product.scala

Listing 2.32. Validate and save—app/controllers/Products.scala

Listing 2.33. Validate and save 2—app/controllers/Products.scala

Listing 2.34. New-product action—app/controllers/Products.scala

Chapter 3. Deconstructing Play application architecture

Listing 3.1. Initial minimal configuration file—conf/application.conf

Listing 3.2. Using the Play API to retrieve the current application’s configuration

Listing 3.3. Accessing a subconfiguration

Listing 3.4. Domain model classes—app/models/models.scala

Listing 3.5. A minimal HTML document—app/views/minimal.scala.html

Listing 3.6. Template with a title parameter—app/views/title.scala.html

Listing 3.7. Compiled template title.template.scala

Listing 3.8. Pick list template—app/views/pickList.scala.html

Listing 3.9. Pick list controller—app/controllers/PickLists.scala

Listing 3.10. Pick list controller—app/controllers/PickLists.scala

Listing 3.11. Global settings object—app/Global.scala

Listing 3.12. Pick list generation actor—app/Global.scala

Listing 3.13. Suspend an HTTP request—app/controllers/Dashboard.scala

Chapter 4. Defining the application’s HTTP interface

Listing 4.1. A controller class with four action methods

Listing 4.2. Servlet API method to handle a request with a numeric parameter

Listing 4.3. Bar code controller action—app/controllers/Products.scala

Chapter 5. Storing data—the persistence layer

Listing 5.1. Schema creation

Listing 5.2. The model

Listing 5.3. Convert the query results to entities

Listing 5.4. Use a pattern to convert query results

Listing 5.5. Parse a product

Listing 5.6. Products with stock items

Listing 5.7. Inserting records

Listing 5.8. Update and delete

Listing 5.9. Initialize Squeryl

Listing 5.10. The model

Listing 5.11. Define the schema

Listing 5.12. Idiomatic schema

Listing 5.13. A nested query

Listing 5.14. Using transactions

Listing 5.15. Stateless relations version of our model

Chapter 6. Building a user interface with view templates

Listing 6.1. Play 1 Groovy template

Listing 6.2. Play 1.x with Java controller example

Listing 6.3. Play 1.x Groovy template

Listing 6.4. Play 2 Scala template

Listing 6.5. Play 2 with Scala controller example

Listing 6.6. Full HTML for the catalog page

Listing 6.7. Catalog page with navigation extracted

Listing 6.8. Extracted page layout

Listing 6.9. The extracted main template

Listing 6.10. Refactored catalog template

Listing 6.11. Extracted product list

Listing 6.12. main template with cart summary

Listing 6.13. Providing an implicit cart

Chapter 7. Validating and processing input with the forms API

Listing 7.1. Play 1.x example: User creation HTML form

Listing 7.2. Play 2 Form to validate a request from the HTML form of listing 7.1

Listing 7.3. Add Product form simplified HTML

Listing 7.4. Action method create, which tries to bind the form from the request

Listing 7.5. Template that uses form helpers to generate an HTML form

Listing 7.6. HTML generated by form helpers for the product form

Listing 7.7. Product form with validation errors and old values

Listing 7.8. Field with custom class and attribute

Listing 7.9. FieldConstructor for Twitter bootstrap

Listing 7.10. The bootstrap package object with an implicit FieldConstructor

Listing 7.11. Product form using custom FieldConstructor

Listing 7.12. Form with validation on multiple fields

Listing 7.13. Inline nested forms

Listing 7.14. Definition of Play’s Formatter trait

Listing 7.15. LocalDate formatter

Listing 7.16. Messages file

Listing 7.17. Using the ignored mapping and custom validation to validate file uploads

Chapter 8. Building a single-page JavaScript application with JSON

Listing 8.1. Override Twitter Bootstrap—public/stylesheets/main.css

Listing 8.2. The model—app/models/Product.scala

Listing 8.3. The application’s single-page template—app/views/index.scala.html

Listing 8.4. list action returns a JSON array—app/controllers/Products.scala

Listing 8.5. HTTP routes configuration—conf/routes

Listing 8.6. Nested JSON structure constructed from JSON library case classes

Listing 8.7. HTML table element data placeholder—app/views/index.scala.html

Listing 8.8. Client application to load data from the server—products.coffee

Listing 8.9. Desired output—JSON representation of a Product object

Listing 8.10. Output product details in JSON format—app/controllers/Products.scala

Listing 8.11. Writes[Product] implementation

Listing 8.12. Writes[Product] implementation using JsPath

Listing 8.13. Alternative Writes[Product] that exposes purchase_price

Listing 8.14. HTML table element data placeholder—app/views/index.scala.html

Listing 8.15. Client that adds product details to each row—products.coffee

Listing 8.16. Make the table editable and update via the server—products.coffee

Listing 8.17. Controller action to save product details—Products.scala

Listing 8.18. Reads[Product] implementation

Listing 8.19. Reads[Product] implementation

Listing 8.20. Format[Product] implementation

Listing 8.21. Sample product JSON structure

Listing 8.22. Corresponding model class structure

Listing 8.23. JSON parser definitions

Listing 8.24. Reads[Company] and Reads[Product] with validation rules

Listing 8.25. Controller action to validate and save product details—Products.scala

Listing 8.26. Formatting JSON validation errors for a JSON response

Listing 8.27. Action helper that performs authentication

Listing 8.28. Helper function to extract credentials from a request query string

Listing 8.29. Updated action helper that extracts credentials before authentication

Listing 8.30. Helper function to extract credentials from basic authentication headers

Chapter 9. Play and more

Listing 9.1. The build properties—Build.scala

Listing 9.2. UserService—app/utils/SimpleUserService.scala

Listing 9.3. Controller—app/com/github/playforscala/barcodes/Barcodes.scala

Listing 9.4. Bar code template—app/views/index.scala.html

Listing 9.5. project/Build.scala

Listing 9.6. app/com/github/playforscala/barcodes/BarcodeCache.scala

Listing 9.7. app/com/github/playforscala/barcodes/Barcodes.scala

Listing 9.8. app/com/github/playforscala/barcodes/

Listing 9.9. .../playforscala/barcodes/BarcodesPlugin.scala

Listing 9.10. HAProxy configuration

Listing 9.11. Apache front-end proxy configuration

Listing 9.12. Apache front-end proxy and load-balancing configuration

Chapter 10. Web services, iteratees, and WebSockets

Listing 10.1. tweetList action

Listing 10.2. Tweetlist template

Listing 10.3. Completed Twitter API action method

Listing 10.4. Caching an entire action

Listing 10.5. Signing a request with OAuth

Listing 10.6. Using Twitter’s streaming API with a simple logging iteratee

Listing 10.7. Status page HTML and JavaScript

Listing 10.8. WebSocket action that sends load average every three seconds

Listing 10.9. Unsafe: mutable state defined on the controller

Listing 10.10. Chat application room actor

Listing 10.11. Chat controller

Listing 10.12. Chatroom HTML page

Listing 10.13. Amazon S3 uploading body parser, buildRequest method

Listing 10.14. Amazon S3 body parser

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset