1. Trang chủ
  2. » Công Nghệ Thông Tin

Lift in Action: The Simply Functional Web Framework for Scala potx

426 716 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Cấu trúc

  • Front cover

  • brief contents

  • contents

  • preface

  • acknowledgments

  • about this book

    • Roadmap

    • Who should read this book?

    • Code conventions and examples

    • Author Online

  • about the author

  • about the cover illustration

  • Part 1 — Getting started

    • Introducing Lift

      • 1.1 What is Scala?

      • 1.2 What is Lift?

        • 1.2.1 Lift design goals

        • 1.2.2 View-first design

        • 1.2.3 Community and team

      • 1.3 Lift features

        • 1.3.1 Lift Core and Lift Web

        • 1.3.2 Lift Persistence

        • 1.3.3 Lift Modules

      • 1.4 Summary

    • Hello Lift

      • 2.1 Getting started with SBT

      • 2.2 Your first Lift application

        • 2.2.1 Creating the project

        • 2.2.2 Inspecting the project

        • 2.2.3 Booting the application

      • 2.3 Snippets and templating overview

        • 2.3.1 Snippets

        • 2.3.2 Templating overview

      • 2.4 Summary

  • Part 2 — Application tutorial

    • The auction application

      • 3.1 Application requirements

        • 3.1.1 Frontend

        • 3.1.2 Administration

      • 3.2 Template structure

        • 3.2.1 Design workflow

        • 3.2.2 Template setup

      • 3.3 Data models

        • 3.3.1 Schema definition

        • 3.3.2 Connecting to the database

      • 3.4 Scaffolding

        • 3.4.1 Prototype traits

        • 3.4.2 CRUD generation

      • 3.5 Validation

        • 3.5.1 Definitions

        • 3.5.2 Displaying field errors

      • 3.6 Summary

    • Customers, auctions, and bidding

      • 4.1 Building an auction catalog

        • 4.1.1 Listing auctions

        • 4.1.2 Adding to SiteMap

      • 4.2 Displaying auctions

        • 4.2.1 Auction detail URLs

        • 4.2.2 The AJAX bidding interface

        • 4.2.3 Real-time bidding

      • 4.3 Summary

    • Shopping basket and checkout

      • 5.1 Order creation

        • 5.1.1 Order models

        • 5.1.2 Attributing auctions to customers

      • 5.2 Implementing the basket and checkout process

        • 5.2.1 Implementing the basket

        • 5.2.2 Implementing the checkout

      • 5.3 Collecting payment with PayPal

        • 5.3.1 Environment setup

        • 5.3.2 The Buy Now button

      • 5.4 Summary

  • Part 3 — Lift in detail

    • Common tasks with Lift WebKit

      • 6.1 Templates, snippets, and views

        • 6.1.1 Templates

        • 6.1.2 Snippets

        • 6.1.3 Views

      • 6.2 Managing state

        • 6.2.1 Request and session state

        • 6.2.2 Cookies

      • 6.3 Forms with LiftScreen and Wizard

        • 6.3.1 LiftScreen

        • 6.3.2 Wizard

      • 6.4 Widgets

        • 6.4.1 AutoComplete widget

        • 6.4.2 Gravatar widget

      • 6.5 Summary

    • SiteMap and access control

      • 7.1 Menus and locations

        • 7.1.1 Understanding and implementing locations

        • 7.1.2 Rendering menus

      • 7.2 Location parameters

        • 7.2.1 Default location parameters

        • 7.2.2 Authentication parameters

      • 7.3 Customizing SiteMap

        • 7.3.1 Creating a custom Loc

        • 7.3.2 When to customize SiteMap?

      • 7.4 Summary

    • HTTP in Lift

      • 8.1 HTTP pipeline

        • 8.1.1 HTTP abstraction

        • 8.1.2 Application lifecycle

        • 8.1.3 Request lifecycle

      • 8.2 URL rewriting

        • 8.2.1 Defining a RewritePF

        • 8.2.2 Advanced rewriting

      • 8.3 Dispatching and web services

        • 8.3.1 Using the HTTP dispatch DSL

        • 8.3.2 Basic REST service

        • 8.3.3 Advanced multiformat REST service

      • 8.4 Summary

    • AJAX, wiring, and Comet

      • 9.1 AJAX

        • 9.1.1 JavaScript abstractions

        • 9.1.2 AJAX 101

        • 9.1.3 Sophisticated AJAX

        • 9.1.4 Using JSON forms with AJAX

        • 9.1.5 AJAX with LiftScreen

      • 9.2 Wiring

        • 9.2.1 Formula wiring

      • 9.3 Comet

        • 9.3.1 What are actors?

        • 9.3.2 Basic Comet usage

        • 9.3.3 Comet-based rock-paper-scissors

      • 9.4 Summary

    • Persistence with Mapper

      • 10.1 Setting up a database

        • 10.1.1 Installation and connectivity

        • 10.1.2 Defining Mappers

        • 10.1.3 Relationships

        • 10.1.4 Schema creation and control

      • 10.2 Interacting with Mapper

        • 10.2.1 Creating data

        • 10.2.2 Querying data

        • 10.2.3 Updating and deleting data

        • 10.2.4 Validation and lifecycle callbacks

        • 10.2.5 Display functionality

      • 10.3 Advanced Mapper

        • 10.3.1 Query logging

        • 10.3.2 Transactions

        • 10.3.3 Custom mapped fields

      • 10.4 Summary

    • Persistence with Record

      • 11.1 Common Record functionality

        • 11.1.1 Common Record fields

        • 11.1.2 Integration with LiftScreen and Wizard

      • 11.2 Record for relational databases

        • 11.2.1 Connecting and querying with Squeryl

        • 11.2.2 A bookstore with Squeryl

      • 11.3 Record for NoSQL stores

        • 11.3.1 NoSQL support in Lift

        • 11.3.2 Bookstore with MongoDB

      • 11.4 Summary

    • Localization

      • 12.1 Implementing localization

        • 12.1.1 Implementing locale calculator

        • 12.1.2 Localizing templates and code

      • 12.2 Defining localized resources

        • 12.2.1 Using XML resources

        • 12.2.2 Using Java properties resources

        • 12.2.3 Using custom resource factories

      • 12.3 Summary

    • Distributed messaging and Java enterprise integration

      • 13.1 Distributed programming

        • 13.1.1 Messaging with AMQP

        • 13.1.2 Messaging with Akka

      • 13.2 Integrating Lift into existing Java infrastructure

        • 13.2.1 JPA and Scala EntityManager

      • 13.3 Summary

    • Application testing

      • 14.1 Scala testing frameworks

        • 14.1.1 ScalaTest

        • 14.1.2 Scala Specs

        • 14.1.3 ScalaCheck

        • 14.1.4 Code coverage reports

      • 14.2 Writing testable code

        • 14.2.1 Complexities of testing state

        • 14.2.2 Dependency injection

      • 14.3 Testing strategies

        • 14.3.1 Testing snippets

        • 14.3.2 Testing web services

        • 14.3.3 Testing with Mapper

        • 14.3.4 Testing Comet and AJAX

      • 14.4 Summary

    • Deployment and scaling

      • 15.1 Choosing a servlet container

      • 15.2 Handling state

        • 15.2.1 Sticky session strategies

        • 15.2.2 Distributing critical state

      • 15.3 Choosing a configuration

        • 15.3.1 Single server

        • 15.3.2 Multiple servers

      • 15.4 Deployment tools and techniques

        • 15.4.1 Built-in assistance

        • 15.4.2 Monitoring

      • 15.5 Case studies

        • 15.5.1 Foursquare

        • 15.5.2 Novell Vibe

      • 15.6 Summary

  • appendix A: Introduction to Scala

    • A.1 Variables, values, and immutability

    • A.2 Classes, methods, traits, and functions

      • A.2.1 Classes

      • A.2.2 Traits

      • A.2.3 Methods

      • A.2.4 Functions

    • A.3 Collections

    • A.4 Pattern matching

    • A.5 Implicits

  • appendix B: Configuring an IDE

    • B.1 IntelliJ

    • B.2 Eclipse

  • appendix C: Options and boxes

  • index

    • Symbols

    • A

    • B

    • C

    • D

    • E

    • F

    • G

    • H

    • I

    • J

    • K

    • L

    • M

    • N

    • O

    • P

    • Q

    • R

    • S

    • T

    • U

    • V

    • W

    • X

  • Back cover

Nội dung

The simply functional web framework for Scala Covers Lift 2.x Timothy Perrett MANNING www.it-ebooks.info Lift in Action www.it-ebooks.info www.it-ebooks.info Lift in Action THE SIMPLY FUNCTIONAL WEB FRAMEWORK FOR SCALA TIMOTHY PERRETT MANNING SHELTER ISLAND www.it-ebooks.info To my Dad for teaching me that hard work and dedication can triumph over any problem For online information and ordering of this and other Manning books, please visit www.manning.com The publisher offers discounts on this book when ordered in quantity For more information, please contact Special Sales Department Manning Publications Co 20 Baldwin Road PO Box 261 Shelter Island, NY 11964 Email: orders@manning.com ©2012 by Manning Publications Co All rights reserved No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine Manning Publications Co 20 Baldwin Road PO Box 261 Shelter Island, NY 11964 Development editors: Copyeditor: Typesetter: Cover designer: Katharine Osborne Andy Carroll Dennis Dalinnik Marija Tudor ISBN: 9781935182801 Printed in the United States of America 10 – MAL – 17 16 15 14 13 12 11 www.it-ebooks.info brief contents PART GETTING STARTED 1 Introducing Lift PART ■ ■ Hello Lift 20 APPLICATION TUTORIAL 37 The auction application 39 ■ Customers, auctions, and bidding 60 PART ■ ■ Shopping basket and checkout 83 LIFT IN DETAIL 105 ■ Common tasks with Lift WebKit ■ SiteMap and access control 140 ■ HTTP in Lift 160 ■ AJAX, wiring, and Comet 187 10 ■ Persistence with Mapper 223 11 ■ Persistence with Record 259 v www.it-ebooks.info 107 vi BRIEF CONTENTS 12 ■ Localization 282 13 ■ Distributed messaging and Java enterprise integration 293 14 ■ Application testing 15 ■ Deployment and scaling 317 www.it-ebooks.info 347 contents preface xiii acknowledgments xv about this book xvii about the author xxi about the cover illustration xxii PART GETTING STARTED .1 Introducing Lift 1.1 What is Scala? 1.2 What is Lift? Lift design goals View-first design Community and team 10 ■ 1.3 Lift features 11 Lift Core and Lift Web Lift Modules 17 1.4 Summary 12 ■ 18 vii www.it-ebooks.info Lift Persistence 15 CONTENTS viii Hello Lift 20 2.1 Getting started with SBT 21 2.2 Your first Lift application 23 Creating the project 23 Inspecting the project Booting the application 29 ■ 2.3 Snippets and templating overview Snippets 2.4 31 Summary 31 35 ■ Templating overview 26 33 PART APPLICATION TUTORIAL 37 The auction application 3.1 Application requirements Frontend 3.2 40 ■ 43 ■ Scaffolding 43 Validation Summary ■ Connecting to the database 49 50 50 CRUD generation 53 Displaying field errors 58 ■ 57 Definitions 58 3.6 Template setup Data models 46 Prototype traits 3.5 41 Template structure 43 Schema definition 46 3.4 40 Administration Design workflow 3.3 39 ■ 59 Customers, auctions, and bidding 60 4.1 Building an auction catalog Listing auctions 61 4.2 ■ Displaying auctions 61 Adding to SiteMap 65 66 Auction detail URLs 66 The AJAX bidding interface 68 Real-time bidding 74 ■ ■ 4.3 Summary 82 www.it-ebooks.info CONTENTS ix Shopping basket and checkout 83 5.1 Order creation 84 Order models 84 5.2 ■ Attributing auctions to customers 87 Implementing the basket and checkout process Implementing the basket 5.3 Summary 99 91 Implementing the checkout 93 Collecting payment with PayPal Environment setup 5.4 91 ■ 99 The Buy Now button 102 ■ 103 PART LIFT IN DETAIL 105 Common tasks with Lift WebKit 107 6.1 Templates, snippets, and views Templates 6.2 108 Managing state ■ Snippets 114 Widgets 132 ■ 128 Wizard ■ Cookies 130 Summary 131 135 137 AutoComplete widget 6.5 Views 125 Forms with LiftScreen and Wizard LiftScreen 6.4 ■ 128 Request and session state 6.3 108 137 Gravatar widget ■ 138 139 SiteMap and access control 140 7.1 Menus and locations 141 Understanding and implementing locations Rendering menus 143 7.2 Location parameters 143 146 Default location parameters 147 Authentication parameters 150 7.3 Customizing SiteMap Creating a custom Loc 7.4 Summary 153 153 ■ 159 www.it-ebooks.info When to customize SiteMap? 158 Options and boxes 389 function if the value exists, so let’s simulate this by explicitly passing null to the Option type’s apply method: scala> Option[String](null).map(_.toLowerCase) res2: Option[java.lang.String] = None Notice that the definition is exactly the same as before, but the value is explicitly null The function definition is the same, but it doesn’t explode with a NullPointerException because the function is never executed Option is clever enough to realize that the value is null, so it returns the strongly typed representation of a nonvalue: None These two examples are explicit, but trivial Consider something more likely to crop up within your application Perhaps you query the database for a value, but the value you’re looking for may not exist In that case, it would be a lot better to receive a properly represented result in the form of None than it would be to simply receive null Appendix A (section A.2) describes some of the actions typically associated with collections and data structures within Scala, covering the map and flatMap functions found in most Scala collections Option also sports these methods, and by virtue of map and flatMap it’s possible to use what is known as a for-comprehension as some nice syntactic sugar for interacting with collection types Because Option is also a collection type, using for-comprehensions allows you to chain options together, so that they only fall through to the next function if the value is something Consider the following: scala> for { a val two: Option[Int] = None two: Option[Int] = None scala> for { | a

Ngày đăng: 30/03/2014, 17:20

TỪ KHÓA LIÊN QUAN