• No results found

Grails 1.1. Web Application. Development. Reclaiming Productivity for Faster. Java Web Development. Jon Dickinson PUBLISHING J MUMBAI BIRMINGHAM

N/A
N/A
Protected

Academic year: 2021

Share "Grails 1.1. Web Application. Development. Reclaiming Productivity for Faster. Java Web Development. Jon Dickinson PUBLISHING J MUMBAI BIRMINGHAM"

Copied!
9
0
0

Loading.... (view fulltext now)

Full text

(1)

Grails 1.1 Web

Application

Development

Reclaiming Productivity

for Faster

Java Web

Development

Jon Dickinson

PUBLISHING J

(2)

Table

of

Contents

Preface

1_

Chapter

1:

Getting

Started with Grails 7

Why

Grails? 7

Less

configuration

8

Faster

setup

8

Shorter

develop/test cycle

9 Consistent

development

environment 9

Domain-specific

language

for web

development

10

Fewer

dependencies

10

Installing

Grails 11

Build a team communication

portal

14

Summary

15

Chapter

2:

Managing

Users with

Scaffolding

17

What is

scaffolding?

17 Createthe domain classes 18

Create the User domain class 19

Create the Roledomain class 20

Creating

controllers to enable

scaffolding

21

Control

through

constraints 25

Meeting

the relations 29

Relating

roles and users 29

Ordering

fieldsthrough constraints 31

Bootstrapping

demo data 31

Summary

33

Chapter

3:

Posting Messages

35

Message

domain class 36

Rendering

a form 37

(3)

TabicofContents

Groovy

ServerPages Create message view

Grailslayouts

Show the form

Handling userinput

Binding the requestto thedomain

Validate and save

Flash scope Redirect

Render validation errors

Feedbackto theuser

Createa home page

HomeController

List all messages

Home page view

Styles

and

navigation

Setthe default page

Update the layout

Tidying up HTMLencoding

Overriding

validation error messages

Summary

Chapter 4: Introduction to Groovy

What is

Groovy?

59

Object-Oriented

60

Dynamic

60

Functional 61

Loosely typed and strongly typed 61

Why Groovy? 62

Familiar syntax 62

Direct integration with Java 62

Running Groovy

63

Installing Groovy

63

Groovy

shell 65

Groovy

console 66

Execute Groovy scripts 66

Groovy classes and scripts 67

GroovyFeatures 68 Semicolons 68

Strings

69 Numbers 70 37 38 39 39 41 42 43 44 44 45 46 48 48 48 49 52 52 52 54 55 57 58 59

(4)

TableofContents

Lists 72

Maps 74

Ranges

75

Truth and equality 76

Closures 77

Plain old

Groovy objects

78

Metaprogramming

79

Adding dynamicbehavior 80

The great pretender

80

Builders 81

Summary

83

Chapter

5: Authentication with

JSecurity

Plug-in

85 Where tofind

plug-ins

86

Installing

a plug-in 86

Configuring JSecurity plug-in

88

How does

JSecurity

work? 88

More aboutrealms 89

Create a

simple

realm 90

Implementauthenticate 91

Dynamicfinders 92

Implement hasRole 94

Install the authentication controller 94

The authenticationfilter 95

Password

encryption

97

Add the

missing

pieces 99

Encryption

of users'

passwords

99

Permission denied page 101

Sign out link 103

Who posted that? 105

Relate messages to users 106

Making

it

happen

107

Showing

the user 108

Hibernate lazy loading 109

Eagerload users 110

Summary

111

Chapter 6:

Testing

113

Writing

unit tests 114

Why wewrite unittests 114

Confidencein code 114

Improve design 114

Developerproductivity 114

(5)

TableofContents

How towriteunit tests 115

Test discreet units of code H5

Trust your libraries 115

Test yourproductioncode 116

Descriptivetestnames 116

Testonethingatatime 117

JUnit refresher 117

SetUp and TearDown 118

Asserting expectations 118

Unittests in Grails 119

Groovytestextensions 119

Create a

grails

test 121

Running

our tests 121

Grailstesting

plug-in

122

Testing Metacontroller 123

Testingvalidation 127

Limitations of Grails in unit tests 128

Integration testing 128

External

dependencies

129

Repeatable

tests 129

Integration

tests in Grails 129

Bootstrap

for environments 130

Functional testing 132

Environment setup 132

Repeatable

tests 133

Test performance 133

Fragility of tests 133

Makingtests understandable 133

Functional

testing

In Grails 134

Benefits of functionaltesting in Grails 134

Installing

thefunctionaltesting plug-in 134

Testing guidance

136

Summary 137

Chapter

7: File Sharing 139

File domain

object

139

FileController 140

File Upload GSP 141

Saving

the file 143

Grails file

upload

143

Thesave action 143

Validation messages 145

(6)

TableofContents

Modeling

for

efficiency

147

Downloading

files 149

Summary

150

Chapter

8: More GORM and Criteria 151

Sort order of

relationships

153

Update

validation messages 153

Querying

with criteria 153

Comparing

criteria and

dynamic

finders 154

Using

logical

operators 155

Querying

across

relationships

155

Specifying

afetchmode for

relationships

156

Criteria reference 156

Logical

criteria 158

Setting

criteria properties 158

Updating

FileController 159

Updating

the create file view 159

Handling

save 160

Render file versions 161 Fixfiledownload 164

Summary

164

Chapter

9: Services 165

Introducing

services 165

Dependency injection

166 Service scope 167

Implementing

FileService 168

Summary

172

Chapter

10:

Managing

Content

through Tagging

173

Add basic

tagging

173

Tagging

domain model 174

TheTag class 174

TheTaggerclass 174

Tagging

a message 176

Tagging

afile 178

GORM inheritance 179

Taggable superclass 181

Polymorphic queries 182

Exposing

tagging

to the users 185

Add theTags inputfield 185

Addmultiple tagstoTaggable 186

Savingthe userstags 186

Displaying tags 187

(7)

TableofContents

Customize the home page 189

Introducing

templates 189

Passing

data to a

template

190

Renderamap "191

Renderanobject "191

Renderacollection 191

Template

namespace 192

Create the message and file templates 192

User

tags

193

Usertotag relationship 193

User ProfileController 194

ThemyTagsform 195

Personalizing the home page 196

Content service 196

UpdatetheHomeController 199

Updatethe home page 199

All Messages and Files 201

Summary

204

Chapter 11: AJAX and RIA Frameworks 205

Edittags inline 205

The remoteLinktag 206

The formRemote tag 207

Taggable controller 208

Tag

views 209

Tagging

domain

changes

211

Include the

Prototype library

211

Try

itout 212

Auto-complete

tags 213

Installing the RichU I 213

Implementthe

auto-complete

214

Suggest tagsaction 214

RichUI autoComplete widget 215

Introducing

tag clouds 219

RichUI tag cloud

component

219

Fetch thetag cloud map 221

Filterby tags 221

Rendering

thetag cloud 224

Summary

225

Chapter

12:

Searching,

RSS, and REST Services 227

Searching

227

Make our

objects

searchable 228

(8)

Tableof Contents

Site-wide search 229

Create the search controller 230

Viewthe search results 231

Updatethetemplates 232

More

searching

234

RSS 235

A note about builders 235

Create the RSS feed 236

Remove authorization check 238

REST services 239

REST overview 239

URL mapping 240

Mapping to variables 241

Mapping toHTTP responsecodes 241

Mapping toHTTP methods 241

REST servicemappings 242

Mapping to wildcards 242

Applying constraints 242 OurMessageAPI mapping 243

Implementing

the RESTful controller 243

Retrieving messages 244

Creatingnew messages 245

Authentication for RESTAPI 247

A test

script

248

Summary

250

Chapter

13: Build Your Own Plug-in 251

Thetagger

plug-in

251

Extractthetagging code 253

Accessing

plug-in templates

through

Tag Libraries 253

Calling

tagsfrom controllers 255

Current limitations 256

Packaging

a

plug-in

256

Using plug-in

events 257

Grails plug-in

lifecycle

events 257

doWithSpring 258

doWithWebDescriptor 259

doWithApplicationContext 259

doWithDynamicMethods 259

onChange andonConfigChange 259

Inspecting

Grailsartifacts 260

TheGrailsApplication class 260

Find Taggabledomain classes 261

Re-modeling

tag

relationships

262

(9)

TableofContents

GroovyMetaClass 263 Gettingthe homepageworking

Items ofInterest

^70

Create messagesandfiles 272

Updatetags 274

List messagesandfiles 1'°

RSS 280

Summary 280

Chapter14:

Deployment

and the Real World 283 Set up the environment 283

Install

MySQL

283

Install Tomcat 284

Configure Grails 285

Set up theDataSource 285

DataSourceconfiguration 285

Environmentallyaware 286

Database management 287

UpdateyourDB configuration 288

Control thebootstrap 289

Package

the WAR file 291

Deploy 292

Hosting options 292

Nextsteps 292

Java Hibernate classeswith GORM 292

Integrating

with otherpresentation frameworks 293

Data migration 294

Summary

295

References

Related documents

Expression of resistance to pod borer, Helicoverpa armigera (Lepidoptera: Noctuidae) in relation to HPLC fingerprints of leaf exudates of

A shrinking labor force is the number one challenge facing the global hospitality industry, according to the International Society of Hospitality Consultants, which recently

It provides the evidence of moderate level of job satisfaction among the healthcare professionals with factors such as opportunity to develop, responsibility, patient

While recording, each Browser Action is captured (for example, Click, Type, Drag and Drop, etc.) and automatically added to the test clip that is being created.. You can also

To substantiate the proposed distributed data management systems for smart grid implementation on a proof-of-concept demonstration..

For many people management processes, whether it’s managing an induction, a performance appraisal, handling a disciplinary situation, or addressing a persistent absenteeism issue, the

Changes in sensory attributes over time after harvest were observed and all 9:00hrs samples were rated highly for each attribute compared to the 12:00hrs and 15:00hrs samples

the test. After the test is done the proctor will scan and email me the answers and destroy the printed copy. 5) Because it takes some time to communicate with