List of Listings

Chapter 1. An introduction to Play

Listing 1.1. Files in a new Play application

Chapter 3. A basic CRUD application

Listing 3.1. Adding action methods

Listing 3.2. Adding routes for our product catalog

Listing 3.3. /app/models/Product.java

Listing 3.4. Adding some test data to /app/models/Product.java

Listing 3.5. Data access methods on the Products class

Listing 3.6. /app/views/products/list.scala.html

Listing 3.7. for loop generating the product descriptions

Listing 3.8. Rendering the list template

Listing 3.9. Product form /app/views/products/details.scala.html

Listing 3.10. Rendered input elements

Listing 3.11. Product binding

Listing 3.12. Adding a pattern constraint

Listing 3.13. A better save implementation

Listing 3.14. Displaying flash success and error messages

Listing 3.15. Implementing the details method

Listing 3.16. The delete() action method

Listing 3.17. Updated template—app/views/products/list.scala.html

Chapter 5. Controllers—handling HTTP requests

Listing 5.1. Project directory overview

Listing 5.2. Products class definition

Listing 5.3. The list() action method

Listing 5.4. The action methods in Products

Listing 5.5. Displaying our stock items

Listing 5.6. Project directory structure

Listing 5.7. A conventional Servlet method

Listing 5.8. Our current routes file

Listing 5.9. /app/utils/ExceptionMailer.java

Listing 5.10. /app/controllers/CatchAction.java

Listing 5.11. CatchAction using configuration

Listing 5.12. Project structure

Chapter 6. Handling user input

Listing 6.1. The “new product” form template

Listing 6.2. Displaying a form with preset values

Listing 6.3. /products/details.scala.html

Listing 6.4. The save() action method

Listing 6.5. Project directory structure

Listing 6.6. /app/models/Tag.java

Listing 6.7. Adding mock data to Tag.java

Listing 6.8. Product save method with tag relationship

Listing 6.9. Project directory structure

Listing 6.10. Product class that is PathBindable-aware

Listing 6.11. Project directory structure

Listing 6.12. Product class that is QueryStringBindable-aware

Listing 6.13. Project directory structure

Listing 6.14. Registering a DateFormatter class

Listing 6.15. The DateFormat annotation, /app/utils/DateFormat.java

Listing 6.16. The AnnotationDateFormatter class

Listing 6.17. Registering our AnnotationDateFormatter in the Global.java file

Listing 6.18. Object model using the DateFormat annotation

Listing 6.19. Accessing the request body

Listing 6.20. Specifying a specific body parser to use

Listing 6.21. Using the as() helper method

Listing 6.22. Using the body.asText() method

Listing 6.23. Save action method with validation

Listing 6.24. EAN number ad hoc validation adding the validate method

Listing 6.25. EAN number validation using the @ValidateWith annotation

Listing 6.26. Custom JSR-303 EAN annotation

Listing 6.27. Custom JSR-303 validator

Listing 6.28. Source code for the field helper template

Listing 6.29. Adding a picture to the Product object model

Listing 6.30. “Product create” form with picture uploading

Listing 6.31. Obtaining and saving uploaded files

Listing 6.32. Our picture method

Chapter 7. Models and persistence

Listing 7.1. Person with getName()

Listing 7.2. Person with a public name property

Listing 7.3. Our basic data model, represented in classes

Listing 7.4. Mapping the Product class

Listing 7.5. Starting the H2 console

Listing 7.6. Mapping the StockItem–Product many-to-one relationship

Listing 7.7. Saving the StockItem and its relationship

Listing 7.8. Making the Product–StockItem relationship bidirectional

Listing 7.9. StockItem.java

Listing 7.10. Warehouse.java

Listing 7.11. Adding address properties to Warehouse

Listing 7.12. Address.java

Listing 7.13. Warehouse.java

Listing 7.14. Warehouse.java

Listing 7.15. Address.java

Listing 7.16. Tag

Listing 7.17. Product.java

Listing 7.18. Our current Product model class EAN lookup

Listing 7.19. Updated findByEan implementation

Listing 7.20. New save() implementation

Listing 7.21. Evolution script structure

Listing 7.22. The new onStart() method on the Global class

Listing 7.23. The initial-data.yml file

Listing 7.24. StockItems controller, /app/controllers/StockItems.java

Listing 7.25. The find method on StockItem

Listing 7.26. find() method with pagination support

Listing 7.27. list.scala.html view

Listing 7.28. JPA appDependencies

Listing 7.29. persistence.xml

Chapter 8. Producing output with view templates

Listing 8.1. Play 1.x Groovy template

Listing 8.2. A type-safe Scala template

Listing 8.3. list.scala.html

Listing 8.4. Looping over the products list

Listing 8.5. Looping over a Map

Listing 8.6. Iteration with index variable

Listing 8.7. If/else statements

Listing 8.8. More concise statements

Listing 8.9. Full HTML for the catalog page, /app/views/catalog.scala.html

Listing 8.10. Catalog page with navigation extracted

Listing 8.11. Extracted page layout

Listing 8.12. The extracted main template

Listing 8.13. Refactored catalog template

Chapter 9. Asynchronous data

Listing 9.1. Project directory structure

Listing 9.2. Model that simulates a report generation

Listing 9.3. Controller that executes report generation in parallel

Listing 9.4. views/report.scala.html view file

Listing 9.5. Streaming expedited orders: Application controller

Listing 9.6. The ExpeditedOrders service

Listing 9.7. The Order model class

Listing 9.8. The scheduler onReceive method

Listing 9.9. Comet client-side implementation (our view)

Listing 9.10. liveUpdate

Listing 9.11. ExpeditedOrders listing with Comet implementation

Listing 9.12. Client-side Comet implementation (our view)

Listing 9.13. Basic WebSocket example

Listing 9.14. Basic WebSocket example, client-side view

Listing 9.15. Server-side listing of our WebSocket application

Listing 9.16. The server-side component that notifies our clients

Listing 9.17. Client-side WebSocket part of our application

Chapter 10. Security

Listing 10.1. build.sbt

Listing 10.2. Global.java

Listing 10.3. BasicAuthenticationFilter.java

Listing 10.4. Global.java

Listing 10.5. Displaying the login form

Listing 10.6. login.scala.html

Listing 10.7. User.java

Listing 10.8. The authenticate method

Listing 10.9. Secured.java

Chapter 11. Modules and deployment

Listing 11.1. The build properties—build.sbt

Listing 11.2. Simple UserService—app/utils/SimpleUserService.java

Listing 11.3. app/com/github/playforjava/barcodes/Barcodes.java

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

Listing 11.5. build.sbt

Listing 11.6. Directory structure of our application and sub-applications

Listing 11.7. Directory structure of our application and sub-applications

Listing 11.8. HAProxy configuration

Listing 11.9. Apache front-end proxy configuration

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

Chapter 12. Testing your application

Listing 12.1. ApplicationTest.java

Listing 12.2. Running our test

Listing 12.3. FunctionalTest.java

Listing 12.4. FunctionalTest.java—authenticateSuccess

Listing 12.5. Not working FunctionalTest.java

Listing 12.6. FunctionalTest.java—listProductsOnTheFirstPage

Listing 12.7. listProductsOnTheFirstPageWithRouter

Listing 12.8. Testing using a test server

Listing 12.9. A simple test for an HTTP call

Listing 12.10. IntegrationTest.java

Listing 12.11. Testing the presence of the product list

Listing 12.12. Testing interaction

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

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