Beginning Groovy, Grails and Griffon. Vishal Layka Christopher M. Judd Joseph Faisal Nusairat Jim Shingler

Similar documents
Index. hashing techniques, 191 plugins, 194 spring security, 207 Aspect-oriented programming (AOP), 149 asperreports, 259 Auto marshalling, 246

Spring Persistence. with Hibernate PAUL TEPPER FISHER BRIAN D. MURPHY

Pro JavaScript. Development. Coding, Capabilities, and Tooling. Den Odell. Apress"

Groovy & Grails Scripting for Modern Web Applications. Rohit Nayak Talentica Software

"Charting the Course... MOC A: Developing with the SharePoint Framework. Course Summary

Contents in Detail. Foreword by Xavier Noria

foreword xvii preface xix acknowledgments xxi about this book xxiv about the title xxviii about the cover illustration

Adobe Experience Manager

Selenium Online Training Brochure

Table of Contents. Introduction... xxi

"Charting the Course... Java Programming Language. Course Summary

Introduction... xv SECTION 1: DEVELOPING DESKTOP APPLICATIONS USING JAVA Chapter 1: Getting Started with Java... 1

Contents at a Glance

object/relational persistence What is persistence? 5

Pro Spring MVC. Marten Deinum Koen Serneels. With Web Flow. Spring Web Flow project founder. Foreword by Erwin Vervaet,

Pro ASP.NET MVC 2 Framework

Introduction to Web Application Development Using JEE, Frameworks, Web Services and AJAX

"Charting the Course... SharePoint 2007 Hands-On Labs Course Summary

Django with Python Course Catalog

foreword to the first edition preface xxi acknowledgments xxiii about this book xxv about the cover illustration

JAVA COURSES. Empowering Innovation. DN InfoTech Pvt. Ltd. H-151, Sector 63, Noida, UP

IN PRACTICE. Daniele Bochicchio Stefano Mostarda Marco De Sanctis. Includes 106 practical techniques MANNING

"Charting the Course... MOC A Developing Data Access Solutions with Microsoft Visual Studio Course Summary

Building Grails Applications with PostgreSQL. Brent Baxter and Ken Rimple PostgreSQL East - March 25, 2010

What s new in Grails 2.0?

Groovy & Grails in Depth

Application Development

Groovy, but without a cheesy presentation title...

CHAPTER 1: INTRODUCING C# 3

Course Outline. ProTech Professional Technical Services, Inc. Comprehensive Angular 7 Course Summary. Description

Enterprise JavaBeans 3.1

Getting. Started with. smash. IBM WebSphere. Ron Lynn, Karl Bishop, Brett King

Groovy For Java Programmers

Oracle Fusion Middleware 11g: Build Applications with ADF Accel

INTRODUCTION TO.NET. Domain of.net D.N.A. Architecture One Tier Two Tier Three Tier N-Tier THE COMMON LANGUAGE RUNTIME (C.L.R.)

1 CUSTOM TAG FUNDAMENTALS PREFACE... xiii. ACKNOWLEDGMENTS... xix. Using Custom Tags The JSP File 5. Defining Custom Tags The TLD 6

MEAN Stack. 1. Introduction. 2. Foundation a. The Node.js framework b. Installing Node.js c. Using Node.js to execute scripts

ADVANCED JAVA COURSE CURRICULUM

"Charting the Course... WebSphere Portal 8 Development using Rational Application Developer 8.5. Course Summary

Practical Node.js. Building Real-World Scalable Web Apps. Apress* Azat Mardan

"Charting the Course... Comprehensive Angular 5. Course Summary

Java SE7 Fundamentals

John Hunt and Alex McManus. Key Java. Advanced Tips and Techniques

Scripting for the JVM using Groovy. Adil Khan Sr. Application Developer /Java Group Biomedical Informatics

Selenium Testing Course Content

This course is designed for web developers that want to learn HTML5, CSS3, JavaScript and jquery.

Courses For Event Java Advanced Summer Training 2018

Contents. Chapter 1: Introducing Spring Persistence...1 Persistence...2 Spring as a de Facto Standard...4

An Introduction to JavaScript & Bootstrap Basic concept used in responsive website development Form Validation Creating templates

"Charting the Course... Comprehensive Angular 6 Course Summary

CONTENTS. INTRODUCTION xvii

Call: JSP Spring Hibernate Webservice Course Content:35-40hours Course Outline

Contents. Deployment: Automated Installation of Cygwin

1.2 Wicket in a nutshell 10 Just Java 11 Just HTML 12 The right abstractions 13

Contents. Contents... XI

10267A CS: Developing Web Applications Using Microsoft Visual Studio 2010

DOT NET Syllabus (6 Months)

Programming in Scala Second Edition

Java EE 7: Back-End Server Application Development

Java EE Application Assembly & Deployment Packaging Applications, Java EE modules. Model View Controller (MVC)2 Architecture & Packaging EJB Module

Federated Identity Manager Business Gateway Version Configuration Guide GC

COPYRIGHTED MATERIAL. Acknowledgments...v Introduction... xxi

JAVA. 1. Introduction to JAVA

Mischa Kölliker. JavaLounge Zürich, 23. Juni 2009

Page 1

Banner Student. Banner Student: Communication Plan, Population Selection and Letter Generation. Description

"Charting the Course to Your Success!" MOC B Programming in C# Course Summary

Spring & Hibernate. Knowledge of database. And basic Knowledge of web application development. Module 1: Spring Basics

Oracle Fusion Middleware

.NET Advance Package Syllabus

Ruby on Rails for PHP and Java Developers

How to Guide. Create a Data Set. Version: Release 3.0

Oracle Data Integrator 11g: Advanced Integration and Development Student Guide

RESTful Java with JAX-RS

Struts: Struts 1.x. Introduction. Enterprise Application

Oracle - Developing Applications for the Java EE 7 Platform Ed 1 (Training On Demand)

Type of Classes Nested Classes Inner Classes Local and Anonymous Inner Classes

"Charting the Course... MOC Programming in C# with Microsoft Visual Studio Course Summary

Managed. Code Rootkits. Hooking. into Runtime. Environments. Erez Metula ELSEVIER. Syngress is an imprint of Elsevier SYNGRESS

"Charting the Course... Oracle 18c PL/SQL (5 Day) Course Summary

Oracle Data Integrator: Administration and Development Volume I Student Guide

Contents. Acknowledgments

JavaScript Patterns O'REILLY* S toy an Stefanov. Sebastopol. Cambridge. Tokyo. Beijing. Farnham K8ln

Getting started with Convertigo Mobilizer

Business Component Development with EJB Technology, Java EE 5

com Spring + Spring-MVC + Spring-Boot + Design Pattern + XML + JMS Hibernate + Struts + Web Services = 8000/-

CONTENTS. Cisco Internet Streamer CDS 3.0 Software Configuration Guide iii OL CHAPTER 1 Product Overview 1-1

OracleAS 10g R3: Java Programming

Contents at a Glance. vii

A guide to learning the popular JVM programming language, Groovy 2.x, and its ecosystem

JAVA SYLLABUS FOR 6 MONTHS

Copyright 2016 Pivotal. All rights reserved. Cloud Native Design. Includes 12 Factor Apps

Acknowledgments... xix

Getting MEAN. with Mongo, Express, Angular, and Node SIMON HOLMES MANNING SHELTER ISLAND

"Charting the Course... MOC A Introduction to Web Development with Microsoft Visual Studio Course Summary

10264A CS: Developing Web Applications with Microsoft Visual Studio 2010

"Charting the Course... Comprehensive Angular. Course Summary

Pro JPA 2. Mastering the Java Persistence API. Apress* Mike Keith and Merrick Schnicariol

Contents. Using Interpreters... 5 Using Compilers... 5 Program Development Life Cycle... 6

Introduction to PHP. Handling Html Form With Php. Decisions and loop. Function. String. Array

Transcription:

Beginning Groovy, Grails and Griffon Vishal Layka Christopher M. Judd Joseph Faisal Nusairat Jim Shingler

Contents J About the Authors About the Technical Reviewer Acknowledgments xv xvii xix Chapter 1: Introduction to Groovy 1 Installation 1 Groovy by Example 2 Converting Java to Groovy 3 Converting a JavaBean to a GroovyBean 4 Simplifying the Code 5 Using Groovy Collection Notation and Closure 5 Getting Rid of maino 6 Groovy Language Key Features 7 Assertion 7 Annotations for AST Transformation 7 Builder 8 Closure 8 GDK 8 Metaprogramming 8 Native Support for Lists and Maps 10 Native Support for Regular Expression 10 Object Orientation: Everything is an Object in Groovy 10 String interpolation 10 Static and Dynamic Typing 11 Static Type Checking 11 V

il CONTENTS Static Compilation 12 Optional Syntax 12 Summary 14 Chapter 2: Groovy Basics 15 Scripts 15 Using Script Functions 16 Compiling Groovy 16 Running Groovy 17 Assertions 21 Power Asserts 22 Strings 22 GStrings 23 Single Line Strings 23 Multiline Strings 24 Slashy Strings 25 Multiline Slashy Strings 25 Dollar Slashy Strings 26 Regular Expressions, 28 Groovy Regular Expression Operators 30 Common Uses of Regular Expressions 32 Collective Datatypes 33 Arrays 33 Lists 34 Maps 35 Ranges 36 Sets 37 Control Structure 38 Groovy Truth 38 Logical Branching 39 Looping 39 Exception Handling 40 vi

CONTENTS Methods 41 Closures 41 Implicit Variables 44 Explicit Declaration of Closure 46 Reusing the Method as a Closure 46 Closures and Collection 47 Closures as Map Keys and Values 48 Currying Closure 49 Closure Trampoline 50 Closure Memoization 50 Operators 51 Operator Overloading 51 Specialized Operators 52 Summary 56 Chapter 3: More Advanced Groovy 57 Object Orientation in Groovy 57 Classes and Scripts 57 Groovy Constructors 59 Inheritance 61 Polymorphism 64 Groovy Unit Testing 64 Working with XML 66 Writing XML with Java 66 Groovy Builders 68 Writing XML with Groovy MarkupBuilder 69 Reading XML with XmlSlurper 69 Native JSON support 69 Reading JS0N 70 JsonBuilder 70 Prettyprinting JSON Content 70 vii

CONTENTS Generating Text with Templates 71 Runtime Metaprogramming 73 Metaobject Protocol 73 Metaclass 73 Using invokemethodo and get/setpropertyo 74 Using methodmissingo 75 Expandos 76 ExpandoMetaClass 76 Categories 79 Runtime Mixins 80 Compile-time Metaprogramming 83 AST Transformations 83 Built-in AST Transformations 83 Domain-Specific Languages 88 Summary 88 Chapter 4: Introduction to Grails 89 What Is Grails? 89 Grails Features, 90 Integrated Open Source 91 Grails Architecture 93 Installing Grails 94 Collab-Todo Application 94 Creating Collab-Todo application 97 Running the Application 99 Creating the Controller 101 Testing the Controller 105 Scaffolding 107 Creating a Domain Class 107 Dynamic Scaffolding 109 Static Scaffolding 113 Creating Domain Relationships 116 viii

CONTENTS H2 Console 119 Grails Plugins 121 Grails Interactive Mode 123 Summary 124 Chapter 5: Building the User Interface 125 Starting with the End in Mind 125 Creating the Footer 126 Creating the Topbar 128 Adding More Look and Feel 130 Grails Tags 133 Static Resources 137 Making the Topbar Functional 138 The Login View, 138 The login Action 140 Handling the Login and Logout Actions 140 Externalizing Strings 141 Errors and Validation 143 Flash and Flash Messages 145 Creating an Audit Log Using Action Interceptors 149 Using Filters 151 Summary 154 Chapter 6: Building Domains and Services 155 GORM 155 Collab-Todo's Domain 156 Creating Domain Objects 157 Basic Domain Creation 158 Creating Relationships 160 IX

CONTENTS Overwriting Default Settings 163 Adjusting the Mappings 163 Validation 170 Constraints 171 Calling the Validator 174 Validation Messages 174 Querying the Database 175 GORM's CRUD Support 175 Creating Queries 176 Services 185 Creating a Service 185 Calling the Service 185 Injecting into the Service 186 Initializing the Service 186 Setting a Bean to Be Transactional 187 Service Context Available in the Service 187 Summary 188 Chapter 7: Security in Grails 189 What Is Security? 189 Authentication 190 Access Control 191 An Overview of Grails Security Solutions 193 Custom Security Implementation 194 Registering a User 195 Logging In and Out 200 Securing the Controllers 202 CAS 204 CAS Installation 205 CAS Configuration 205 CAS Usage 206 X

II CONTENTS Spring Security 207 Security Domain Classes 207 Securing URLs 212 SecurityTagLib 214 Summary 215 Chapter 8: Web 2.0 Ajax and Friends 217 Advanced Presentation Components 217 Adding RichText Capabilities 217 Adding Search Capabilities 219 Allowing File Uploads 221 Tag Libraries 228 Creating the Tag Library 228 Referencing the Tag Library 230 Ajax in Grails 230 Using Ajax Frameworks in Grails 231 Dynamic Rendering of Data 234 RSS Feeds 237 Summary 240 Chapter 9: Web Services 241 RESTful Web Services 241 RESTful in Grails 245 URL Mappings 245 Content Negotiation 247 RestController 249 Summary 255 Chapter 10: Reporting 257 The Report 257 Reporting Tools 259 Overview 259 Installing JasperReports and ireports 260 xi

1 CONTENTS Creating the Todo Report 261 Defining the Data Source 261 Using ireports 262 Enhancing the Report 265 Compiling the Report 266 The Report Tag 267 Tag Library Overview 267 Creating the Tag 267 The ReportController and the ReportService 269 Tying It All Together 274 Gathering the Report Data 274 Adding the Report Tag to the Application 274 The Report List 275 An Alternate Approach 276 Summary 277 Chapter 11: Batch Processing 279 Installing the Quartz Plugin 279 Creating a Job 280 Building a Batch-Reporting Facility 282 Creating a Nightly Reporting Job 283 Retrieving the User's Todos 285 Invoking the ReportService 287 Invoking the E-Mail Service 288 Summary 289 Chapter 12: Deploying and Upgrading Grails Applications 291 Deploying Grails Applications 291 Using Environments 291 Understanding Grails Configurations 293 Packaging the Application for Deployment 298 Deploying to an Application Server 298 xii

CONTENTS Upgrading Grails Applications 301 Configuration Changes 302 Command Line Changes 302 H2 302 jquery 302 Controller Public Methods 303 Unit Test Framework 303 Summary 303 Chapter 13: Introduction to Griffon 305 Installing Griffon 305 Creating Your First Application 306 Directory Structure 307 Griffon Application Life Cycle 315 Initialization 315 Startup 316 Ready 316 Shutdown 316 Stop 316 Views 317 Builder Overview 317 Griffon View 319 Special Nodes 323 Models and Bindings 325 Controllers 328 Injected Properties 328 Injected Methods 328 Initialization and Destruction Hook 330 Actions 331 Summary 331 Index 333 xiii