Lift Application Development Cookbook
()
About this ebook
Related to Lift Application Development Cookbook
Related ebooks
JavaScript and JSON Essentials Rating: 5 out of 5 stars5/5Wb Development full course : from zero to web hero Rating: 0 out of 5 stars0 ratingsPHP and MongoDB Web Development Beginner’s Guide Rating: 0 out of 5 stars0 ratingsModern JavaScript Applications Rating: 0 out of 5 stars0 ratingsLearning Modular Java Programming Rating: 0 out of 5 stars0 ratingsGoogle BigQuery Analytics Rating: 3 out of 5 stars3/5Backbase 4 RIA Development Rating: 0 out of 5 stars0 ratingsJavaScript and AJAX For Dummies Rating: 4 out of 5 stars4/5Sencha Touch 2 Mobile JavaScript Framework Rating: 0 out of 5 stars0 ratingsSplunk Developer's Guide Rating: 0 out of 5 stars0 ratingsLearning Ext JS - Fourth Edition Rating: 0 out of 5 stars0 ratingsLearning Mongoid Rating: 0 out of 5 stars0 ratingsLearning NHibernate 4 Rating: 0 out of 5 stars0 ratingsPractical C++ Backend Programming: Crafting Databases, APIs, and Web Servers for High-Performance Backend Rating: 0 out of 5 stars0 ratingsAdvanced GraphSQL Solutions: Strategies and Techniques for Effective Implementation Rating: 0 out of 5 stars0 ratingsHTML5 Data and Services Cookbook Rating: 5 out of 5 stars5/5AJAX and PHP: Building Responsive Web Applications Rating: 4 out of 5 stars4/5RESTful Web API Design with Node.js - Second Edition Rating: 1 out of 5 stars1/5Jasmine JavaScript Testing - Second Edition Rating: 0 out of 5 stars0 ratingsDWR Java AJAX Applications Rating: 0 out of 5 stars0 ratingsMastering Node.js Web Development: Go on a comprehensive journey from the fundamentals to advanced web development with Node.js Rating: 0 out of 5 stars0 ratingsJavaScript: Igniting Business Growth Through Dynamic Web Development Rating: 0 out of 5 stars0 ratingsNeo4j - A Graph Project Story Rating: 5 out of 5 stars5/5jQuery Hotshot Rating: 0 out of 5 stars0 ratingsIntroduction to JVM Languages Rating: 0 out of 5 stars0 ratingsThe FastAPI Handbook: Simplifying Web Development with Python Rating: 0 out of 5 stars0 ratingsExt JS Application Development Blueprints Rating: 0 out of 5 stars0 ratingsFastAPI Cookbook: Develop high-performance APIs and web applications with Python Rating: 0 out of 5 stars0 ratings
Internet & Web For You
The $1,000,000 Web Designer Guide: A Practical Guide for Wealth and Freedom as an Online Freelancer Rating: 4 out of 5 stars4/5More Porn - Faster!: 50 Tips & Tools for Faster and More Efficient Porn Browsing Rating: 3 out of 5 stars3/5How to Be Invisible: Protect Your Home, Your Children, Your Assets, and Your Life Rating: 4 out of 5 stars4/5Coding For Dummies Rating: 5 out of 5 stars5/5Cybersecurity For Dummies Rating: 5 out of 5 stars5/5Surveillance and Surveillance Detection: A CIA Insider's Guide Rating: 3 out of 5 stars3/5Python: Learn Python in 24 Hours Rating: 4 out of 5 stars4/5Kill All Normies: Online Culture Wars From 4Chan And Tumblr To Trump And The Alt-Right Rating: 3 out of 5 stars3/5Coding All-in-One For Dummies Rating: 4 out of 5 stars4/548 Really Useful Web Sites Rating: 5 out of 5 stars5/5Publishing E-Books For Dummies Rating: 4 out of 5 stars4/5WordPress For Dummies Rating: 0 out of 5 stars0 ratingsTor and the Dark Art of Anonymity Rating: 5 out of 5 stars5/5The Digital Marketing Handbook: A Step-By-Step Guide to Creating Websites That Sell Rating: 5 out of 5 stars5/5The Beginner's Affiliate Marketing Blueprint Rating: 4 out of 5 stars4/5Beginner's Guide To Starting An Etsy Print-On-Demand Shop Rating: 0 out of 5 stars0 ratingsWeb Design For Dummies Rating: 4 out of 5 stars4/5Notion for Beginners: Notion for Work, Play, and Productivity Rating: 4 out of 5 stars4/5The Gothic Novel Collection Rating: 5 out of 5 stars5/5Learn NodeJS in 1 Day: Complete Node JS Guide with Examples Rating: 3 out of 5 stars3/5An Ultimate Guide to Kali Linux for Beginners Rating: 3 out of 5 stars3/5Everybody Lies: Big Data, New Data, and What the Internet Can Tell Us About Who We Really Are Rating: 4 out of 5 stars4/5No Place to Hide: Edward Snowden, the NSA, and the U.S. Surveillance State Rating: 4 out of 5 stars4/5Ultimate guide for being anonymous: Avoiding prison time for fun and profit Rating: 5 out of 5 stars5/5SEO For Dummies Rating: 4 out of 5 stars4/5Content Chemistry: The Illustrated Handbook for Content Marketing Rating: 5 out of 5 stars5/5
Reviews for Lift Application Development Cookbook
0 ratings0 reviews
Book preview
Lift Application Development Cookbook - Gilberto T. Garcia Jr.
Table of Contents
Lift Application Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers and more
Why Subscribe?
Free Access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Getting Started with Lift Basics
Introduction
Creating a Lift application using SBT
Getting ready
How to do it...
How it works...
There's more...
See also
Creating a Lift application using Maven
Getting ready
How to do it...
How it works...
See also
Defining a SiteMap
Getting ready
How to do it...
How it works...
There's more...
See also
Logging using logback
Getting ready
How to do it...
How it works...
There's more...
See also
Sending e-mails using Gmail's SMTP server
Getting ready
How to do it...
How it works...
There's more...
See also
2. Working with HTML
Introduction
Transforming HTML elements using their IDs
Getting ready
How to do it...
How it works...
See also
Creating an HTML list using CSS selectors
Getting ready
How to do it...
How it works...
There's more...
See also
Creating an HTML table with dynamically defined columns
Getting ready
How to do it...
How it works...
See also
Nesting snippets
Getting ready
How to do it...
How it works...
See also
Dynamic menu rendering
Getting ready
How to do it...
How it works...
See also
Localizing templates
Getting ready
How to do it...
How it works...
There's more...
See also
Testing snippets using Specs2
Getting ready
How to do it...
How it works...
There's more...
See also
Creating custom error pages
Getting ready
How to do it...
How it works...
There's more...
Sending JavaScript commands from the server
Getting ready
How to do it...
How it works...
There's more...
See also
Invoking server-side functions from the client
Getting ready
How to do it...
How it works...
See also
3. Working with Forms
Introduction
Creating forms
Getting ready
How to do it...
How it works...
There's more...
See also
Validating forms
Getting ready
How to do it...
How it works...
There's more...
Creating an Ajax form
Getting ready
How to do it...
How it works...
There's more...
Creating multipage forms
Getting ready
How to do it...
How it works...
There's more...
See also
Defining a relation between form fields
Getting ready
How to do it...
How it works...
There's more...
4. Working with REST
Introduction
Getting data from the server
Getting ready
How to do it...
How it works...
There's more...
Creating data using the REST service
Getting ready
How to do it...
How it works...
There's more...
See also
Modifying data using the REST service
Getting ready
How to do it...
How it works...
Deleting data using the REST service
Getting ready
How to do it...
How it works...
Testing a REST service using Specs2
Getting ready
How to do it...
How it works...
There's more...
See also
Uploading a file using the REST service
Getting ready
How to do it...
How it works...
Creating an RSS feed
Getting ready
How to do it...
How it works...
See also
5. Working with Databases
Introduction
Configuring a connection to database
Getting ready
How to do it...
How it works...
There's more...
See also...
Mapping a table to a Scala class
Getting ready
How to do it...
How it works...
There's more...
See also...
Creating one-to-many relationships
Getting ready
How to do it...
How it works...
See also...
Creating many-to-many relationships
Getting ready
How to do it...
How it works...
See also...
Creating CRUD features with CRUDify
Getting ready
How to do it...
How it works...
There's more...
Paginating result sets
Getting ready
How to do it...
How it works...
There's more...
Using an in-memory database in application tests
Getting ready
How to do it...
How it works...
There's more...
6. Working with Record
Introduction
Configuring a connection to a database using Squeryl
Getting ready
How to do it...
How it works...
There's more...
See also
Mapping a table to a Scala class
Getting ready
How to do it...
How it works...
There's more...
See also
Migrating the database using Liquibase
Getting ready...
How to do it...
How it works...
See also
Creating one-to-many relationships
Getting ready
How to do it...
How it works...
Creating many-to-many relationships
Getting ready
How to do it...
How it works...
Paginating result sets using Record
Getting ready
How to do it...
How it works...
See also
Testing your application using an in-memory database
Getting ready
How to do it...
How it works...
See also
7. Working with MongoDB
Introduction
Connecting to MongoDB using record
Getting ready
How to do it...
How it works...
Mapping a MongoDB collection to a Scala class
Getting ready
How to do it...
How it works...
See also
Mapping embedded objects
Getting ready
How to do it...
How it works...
There's more...
See also
Mapping referenced objects
Getting ready
How to do it...
How it works...
See also...
Querying with Rogue
Getting ready
How to do it...
How it works...
See also...
8. Integrating Lift with Social Media
Introduction
Signing up using a Facebook account
Getting ready
How to do it...
How it works...
There's more...
See also...
Fetching a user's Facebook data
Getting ready
How to do it...
How it works...
See also...
Signing up using a Gmail account
Getting ready
How to do it...
How it works...
See also...
Fetching a user's Gmail data
Getting ready
How to do it...
How it works...
See also...
Signing up using a LinkedIn account
Getting ready
How to do it...
How it works...
See also...
Fetching a user's LinkedIn data
Getting ready
How to do it...
How it works...
Signing up using a Twitter account
Getting ready
How to do it...
How it works...
See also...
Fetching a user's Twitter data
Getting ready
How to do it...
How it works...
Index
Lift Application Development Cookbook
Lift Application Development Cookbook
Copyright © 2013 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: September 2013
Production Reference: 1190913
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-84951-588-7
www.packtpub.com
Cover Image by Suresh Mogre (<[email protected]>)
Credits
Author
Gilberto T. Garcia Jr.
Reviewers
Diego Medina
Peter Petersson (karma4u101)
Peter Robinett
Paulo Suzart
Acquisition Editor
Vinay Argekar
Lead Technical Editor
Azharuddin Sheikh
Technical Editors
Jalasha D'costa
Akashdeep Kundu
Proshonjit Mitra
Shiny Poojary
Copy Editors
Brandt D'Mello
Mradula Hegde
Gladson Monteiro
Project Coordinator
Angel Jathanna
Proofreaders
Simran Bhogal
Ameesha Green
Indexer
Rekha Nair
Graphics
Abhinash Sahu
Production Coordinator
Nilesh R. Mohite
Cover Work
Nilesh R. Mohite
About the Author
Gilberto T. Garcia Jr. has a Bachelor's degree in Philosophy from USP, and has been working with Internet-related technologies since 1999. He had worked with different programming languages in several projects with different sizes and complexities.
As a person who enjoys learning new things, he started to study and work with Scala and Lift in 2010.
I want to thank my wife, Lavinia, for all the love and encouragement to write this book, and for her support and patience during the writing process. I also want to thank my family and friends.
Thanks to David Pollak for creating Lift, and thanks to the Lift committers and everyone who makes the Lift community such a nice place to be around.
About the Reviewers
Diego Medina lives on the mountains of North Carolina with his wife, daughter, and their three cats. He has been a developer for the past 12 years, and his focus has been on web development and more specifically, web security.
He is a proud Lift committer and a very active member of the Lift community, answering questions on the mailing list as well as writing articles on his personal blog.
Peter Petersson lives in the south of Sweden with his wife and one-year-old boy.
He has been a developer for 18 years. He started his developer career at Ericsson Software Technology mostly using C++, but at the time Java was emerging, he soon jumped onto that bandwagon. He has been a co-owner in a tour operator information system company and is currently a system developer and consultant at Avalon Innovation.
He started looking at Scala and functional programing at the beginning of 2011, about the same time he found Lift to be an awesome web framework. He is a proud Lift committer and creator of the Lift FoBo, Front End Toolkit Module, as well as the jQuery module.
Peter Robinett is a web and mobile developer based in Amsterdam. He is passionate about Scala and is a committer to the Lift project. He works under the name Bubble Foundry, and blogs occasionally at www.bubblefoundry.com.
Paulo Suzart worked in different types of companies in the last 10 years, from e-commerce to insurance, as a Java programmer and lately as an SOA specialist. He currently runs a digital media startup as CTO.
He truly believes that startups are open fields for new technologies and functional programming languages, such as Scala and Clojure.
www.PacktPub.com
Support files, eBooks, discount offers and more
You might want to visit www.PacktPub.com for support files and downloads related to your book.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
Support files, eBooks, discount offers and morehttp://PacktLib.PacktPub.com
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read and search across Packt's entire library of books.
Why Subscribe?
Fully searchable across every book published by Packt
Copy and paste, print and bookmark content
On demand and accessible via web browser
Free Access for Packt account holders
If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access.
Preface
Lift is a web framework built in Scala. Its main goal is to be a secure framework that helps developers to build scalable web applications in a concise and maintainable way.
There are six things—according to the official website, http://liftweb.net/—that makes Lift different from any other web framework available today:
Secure: Lift apps are resistant to common vulnerabilities, including many of the OWASP Top 10 projects
Developer-centric: Lift apps are fast to build, concise, and easy to maintain
Designer-friendly: Lift apps can be developed in a totally designer-friendly way
Scalable: Lift has a number of high-performance apps, and they scale in the real world to handle insane traffic levels
Modular: Lift apps can benefit from easy-to-integrate, pre-built modules
Interactive like a desktop app: Lift's Comet support is unparalleled, and Lift's Ajax support is super easy and very secure
The goal of this book is to introduce you to the basics of Lift, and teach you everything that you need to know to build applications using Lift.
By providing you with hands-on examples, we hope that you find this book useful as your first introduction to Lift, and also as a reference guide when building your own web applications.
What this book covers
Chapter 1, Getting Started with Lift Basics, covers the basics of Lift which include how to start a new application using build tools such as SBT and Maven. It also explains how to define the application structure using SiteMap object and how to use the Mailer object to send e-mails.
Chapter 2, Working with HTML, introduces the reader to CSS selectors and shows how to use them to transform the HTML that will be rendered in the browser. It also covers how to test snippets, how to generate a JavaScript code from the server, and how to invoke server-side functions using JavaScript. It also explains how to localize templates.
Chapter 3, Working with Forms, covers the different ways the reader can work with forms, such as how to create a single page form and a wizard-like form. It also explains how to submit forms using Ajax and how to wire form fields.
Chapter 4, Working with REST, introduces Lift's RestHelper object and how to use it to create a REST API. It also explains how to test the REST API, how to upload files, and how to create an RSS feed.
Chapter 5, Working with Databases, explains how to use Mapper to integrate the application with a database. It also covers the basics of ORM mapping and how to use an in-memory database to test an application that uses Mapper.
Chapter 6, Working with Record, explains how to integrate a Lift application with a database using Record and Squeryl. It also covers how to test an application that uses Record and Squeryl using an in-memory database.
Chapter 7, Working with MongoDB, covers the integration of a Lift application with MongoDB, how to use Record to create such an integration, and explains how to query MongoDB using Rogue.
Chapter 8, Integrating Lift with Social Media, explains how to use social login to authenticate users and how to get their data from their Facebook, Gmail, Twitter, or LinkedIn accounts.
What you need for this book
To be able to follow the recipes, you will need to have Java 7 installed on your computer.
Who this book is for
This book is for developers who want to learn how to develop web applications using the Lift framework. However, we assume that the reader at least knows the basics of Scala, HTML, and JavaScript.
Conventions
In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: The bigger difference lies in the snippet code. You can see that after getting the user data, we've invoked a method called fetchUserData and used its result to change the contents of a li tag.
A block of code is set as follows:
import code.lib.googleSession
import net.liftweb.util.BindHelpers._
import net.liftweb.common.Full
object GmailData {
def render = {
googleSession.get match {
case Full(email) => .email
#> email
case _ => *
#> Not authorized
}
}
}
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
c =>
Any command-line input or output is written as follows:
scala> val transformSpanContent = span *
#> Some Text
New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: If you select a name in the combobox and click on the Delete Selected button, you'll see an alert saying that the name you selected was deleted.
Note
Warnings or important notes appear in a box like this.
Tip
Tips and tricks appear like this.
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.
To send us general feedback, simply send an e-mail to <[email protected]>, and mention the book title via the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.
Customer support
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
Downloading the example code
You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
Errata
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.
Piracy
Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <[email protected]> with a link