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

The definitive guide to grails second edition - phần 10 potx

50 522 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

Thông tin cơ bản

Định dạng
Số trang 50
Dung lượng 260,29 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

■ Note Groovy doesn’t support true named arguments but allows the method to specify a map as the only argument, hence mimicking this capability.. This limitation is mainly down to Java b

Trang 1

Note Groovy doesn’t support true named arguments but allows the method to specify a map as the only argument, hence mimicking this capability This limitation is mainly down to Java byte code itself, which does not associate names (only types) with method parameters.

Groovy ships with a number of builders (excuse the pun) built-in, including but not ited to the following:

lim-• The MarkupBuilder for constructing, typically XML, markup

• The DOMBuilder for constructing W3C DOM trees

• The AntBuilder to provide scripting for Apache Ant

• The SwingBuilder for constructing Swing GUI interfaces

As an example, take a look at the usage of the MarkupBuilder, shown in Listing A-23, which allows construction of markup documents such as XML or HTML

Listing A-23 MarkupBuilder in Action

// construct builder that outputs to standard out

def mkp = new groovy.xml.MarkupBuilder()

// write markup

mkp.authors {

author(name:'Stephen King') {

book( title:'The Shining')

book( title:'The Stand')

}

author(name: 'James Patterson') {

book( title:'Along Came a Spider' )

}

}

This example demonstrates the construction of a groovy.xml.MarkupBuilder instance using standard out and the usage of closures and named arguments to represent the markup Listing A-24 shows the result

Trang 2

Listing A-24 Result of MarkupBuilder

<authors>

<author name="Stephen King">

<book title="The Shining" />

<book title="The Stand" />

</author>

<author name="James Patterson">

<book title="Along Came a Spider" />

</author>

</authors>

It is interesting at this point to take a closer look at Listing A-23 In this example, we passed

an “anonymous” closure to the authors() method of the MarkupBuilder instance, but consider

the possibility of assigning this closure to a variable and then passing as an argument the same

closure to different builders, one that renders XML and another that outputs the same data as

a PDF document or renders it in a GUI

Unlike the XML produced in Listing A-24, the builder code in Listing A-23 is pure Groovy

code and can therefore leverage the full power of the language: conditionals, looping,

referenc-ing, inheritance, and so on

Builders are an extremely powerful concept, and if you’re willing to delve into some

Groovy development by extending the BuilderSupport class to create your own builders, you

can create some pretty amazing constructs that could end up as domain-specific languages

within your application

Grails utilizes builders all over the place, from constructing Hibernate criteria to rendering

markup to the HTTP response Builders are a key element in the conciseness and power that

Grails brings to web application development

Summary

That completes this dash through the Groovy language As we have already admitted, it was by

no means comprehensive Groovy has many more fantastic features; it is really worth investing

the time to learn more about it But this quick overview should give you an idea of why some of

Groovy‘s features are so important to Grails and how they make life easier developing today’s

web applications

You saw that Groovy looks pretty much like Java at first glance, allowing a smooth

transi-tion into the new world of dynamic programming Since Groovy is fully integrated with the Java

platform and works directly on JDK objects, your investment in learning Java and your

experi-ence with the platform are fully protected

What’s new is that Groovy gives you more immediate control over types such as lists and

maps New concepts such as closures and ranges complete the picture The combination of

syntax enhancements, new types, improvements to JDK classes, and metaprogramming leads

to an idiomatic Groovy style that is both simple and powerful

Trang 3

? (safe deference operator), 112_searchResults.gsp template, 196–197

* (spread dot) operator (Groovy), 385

<sysprops> element, passing system properties with, 327

content negotiation with, 452–457reliability of, 456–457

access, restrictingbased on roles, 432through URL mappings, 446–448with <jsec:lacksPermission> tag, 439accessControl method, 428

accessingbusiness logic within application, 298–304request attributes, 68–70

request parameters, 73Acegi plugin, 416

ACID properties of databases, 295action names, removing from URL mapping, 145

Trang 4

action states (flows)

checking login details with, 203, 212–216

after advice (AOP), 90, 91

after attribute (Ajax), 177–178

afterView filter, 418

Ajax

asynchronous form submission, 175–177

effects and animation, adding, 193

enabling on form fields, 193–197

event handling, 178–179

executing code before and after calls,

177–178flow of request, 172

HTML anchor tag, creating, 173–174

login request, handling, 176

overview of, 171performance and, 197–198provider, changing, 174–175remote linking, 179–193XMLHttpRequest object and, 171–173album art, displaying, 182–193

Album Controller, display action, 213Album domain class

creating, 23price property, 209album-art plugin exampleadding method to all controllers, 395–396creating, 391

dependencies, 392getArt() method and, 396providing metadata to, 393structure of, 392

updating to use simple-cache plugin, 394AlbumArtKey cache key class, 188

AlbumArtService templatecreating, 183

enabling caching, 188full code for, 188–190AlbumControllercreate action, 31creating, 24delete action, 29display action, 181edit action, 29index action, 28list action, 28save action, 31, 77show action, 28update action, 30_album.gsp templateadding album art to, 192buy action, 211

implementing, 180with permissions working, 440

Trang 5

animation, adding with Ajax, 193

anonymous code blocks, 552

See also ActiveMQ; Ant

Commons HttpClient project, 473

Ivy, dependency resolution with, 327–330

Appear effect (Scriptaculous library), 193

appender

configuring, 308

using, 309

appending, 554

application layer caching, 373

application reload events, plugins and,

385–387

ApplicationContext, 379

ApplicationContextAware instance, 489

application-layer securityfilters, 417–418JSecurity pluginauthentication realms, 419–420authentication, implementing with, 422–427

filters, 427–429overview of, 416permission-based security, implementing, 433, 446role-based security, implementing, 429–430

roles and permissions, 421subjects and principals, 420view, securing, 431–432working with, 421applications

See also gTunes application

controller, creating, 8–10creating, 7

deploying, 41modularizing with plugins, 397–406object-oriented, and domain model, 45ren-war command, 41

running, 13running tests, 12–13steps in creating, 7structure of, 7testing code, 10–11with WAR file, 41–42applying constraints to URL mappings, 149–150

argumentspaginate tag, 129redirect method, 74around advice (AOP), 90artefact types, 376–379ArtefactHandler interface, 377–378artefacts, supplying with plugins, 373–374Artist class, unit test for, 61

Trang 6

data binding and, 81–82

GORM, overview of, 252–253

one-to-many, 24, 54–56, 521, 522–523

one-to-one, 53–54

many-to-many, 523–524

many-to-one, 81, 521

performance tuning and, 278–281

querying with criteria, 260

relationship management methods,

253–254SortedSet, 252

transitive persistence, 254

asterisk (*)

as spread operator, 259

as wildcard, 150, 197, 417

asynchronous e-mail notifications, 511–513

asynchronous form submission, 175–177

Asynchronous JavaScript Technology and

attacks, securing against

batch data binding, 413–414

redirects and, 71standard, 68audit-logging plugin, 368authenticate method, 422, 424–425authentication

definition of, 407, 417implementing with JSecurity plugin, 422–427

realms, 419–420Authentication plugin, 416AuthFilters class

overview of, 427–428security URI within, 447authorization, 407, 416AuthRealm class, 422–423, 438automatic time stamping, 288automating deployment to Tomcat, 317–320autowiring

configuring beans for, 488overview of, 291, 379 Axis 2 plugin, 479

abstract beans, 495–496bean scopes, 496–497configuring BeanBuilder with, 500–502defining beans, 491–492

dynamically creating beans, 497–498

Trang 7

See also Spring beans

configuring for autowiring, 488

before advice (AOP), 90–91

before attribute (Ajax), 177–178

behaviors, adding at runtime, 563–565

belongsTo property, 54, 254

binary response, writing, 89

bind errors, dealing with, 13

bindData method, 80–81

binding, 109

blog plugin example

adding metadata to, 397

URL mapping to customize layout of, 401

blog posts in gTunes application, creating,

404–405

blog-type URL mapping, 149

Blowfish encryption codec class, 414–415

BootStrap classes, populating database with,

command-line variables, 313–314documenting scripts, 315–316overview of, 310–311

parsing command-line arguments, 314–315

reusing Grails scripts, 316scripts, creating, 312–313build.xml file, 325

builders (Groovy), 567–569BuilderSupport class, 569built-in operators (Groovy), 560

built-in tags See tags, built-in

business logic, accessing within application, 298–304

“Buy” button, disabling, 439buyFlow

defining, 212full code for, 240–244

C

cache key, 187

<cache:text> tag, 382caching

application layer, 373content-level, 382

in GORM, 282–284return value of blocks of code using closures, 381

caching pattern, 380caching solution, Ehcache, 187calling methods on integers, 558cascade behavior, 254

checkBox tag, 120–121chooseGiftWrapFlow flow, 206–207

Trang 8

Person, 51–53Realm, 419SampleController, 65–66SecurityUtils, 420Song, 46, 62SongController, stream action, 513StoreService

creating, 290purchaseAlbums method, 293–294storeService property, 294–295StreamingMarkupBuilder, 322StreamingService, 514–515SubscriptionTagLibimplementing, 507testing, 508–509TagLibUnitTestCaseusing, 508transactional service, 512UrlMappings, 155–158User, 347, 535

UserController, 416UserControllerTests, 100ClassPathXmlApplicationContext instance, 489

clear() method, 269–270clearErrors() method, 48clearing session, 269–270client storage, flows and, 204–205clients, calling SOAP from, 482–484closures

caching return value of blocks of code using, 381

Groovy, 552–553

Trang 9

Find it faste

reusing action states with, 227–231

Cobertura (Source Forge), code coverage

with, 330–331

code, executing before and after calls,

177–178

code blocks, reusable, 552

code coverage, with Cobertura, 330–331

using with flows, 231–235

command-line arguments, parsing, 314–315

release-plugin, 390–391run-app, 13

run-war, 41set-version, 362test-app, 12–13, 61uninstall-pluginl, 370war, 41

Commons HttpClient project (Apache), 473Company class, transient property, 50company table, 50

compilation paths, 314composite identifiers, using, 531–532composition, 59–60

Config.groovy fileenvironment-specific configuration, 306locations setting, 310

log4j property, 306–309overview of, 305–306configuring

ActiveMQ with BeanBuilder, 500–502assigned generator, 531

beans for autowiring, 488composite identifier, 531data sources

DataSource.groovy file, 35–37JNDI, 39

MySQL database, 37–39overview of, 34

Ehcache Spring bean, 187GORM

custom dialect, 264–265Hibernate properties, 265overview of, 263

SQL logging, 264

Trang 10

configuring (continued)

Grails

environment-specific configuration,

306externalized configuration, 310

logging, 306–309

overview of, 305–306

stack trace filtering, 309

Grails build in Hudson, 334

Grails installation in Hudson, 332

domain class with, 166

using with POJO entities, 541–542

constraints block, URL mappings, 144,

149–150constraints property (domain class), 46, 150

consuming JMS messages with Spring,

503–505container, deploying to, 361–362

content negotiation (REST)

overview of, 452

view and, 459–460

with ACCEPT header, 452–457

with CONTENT_TYPE header, 457–458

with file extensions, 458

with request parameters, 459

content-level caching, 382

contentType directive, 109

CONTENT_TYPE header, content

negotiation with, 457–458continuous integration with Hudson,

331–335controllers

See also specific controllers

binary response, writing, 89command objects

defining, 82–83using, 83–84creating, 8–10data bindingassociations and, 81–82bindData method, 80–81Errors API and, 79–80file uploads and, 86–89overview of, 77–78

to multiple domain objects, 80validating incoming data, 78–79default index action of, 10default action, setting, 65–67dynamic scaffolding and, 19–21dynamically mapping to, 451generating, to implement CRUD functionality, 27–31home page, creating, 94–95HTTP method restrictions, 85–86index action, 10

injecting service instance into, 291

IO and, 86logging, 67–68login form, creating, 96–97login process, testing, 104–106LoginCommand class, 102–104mapping to view for particular, 148methods, adding to, 384

model, creating, 75names, removing from URL mapping, 145overview of, 65

prototyped, 65redirecting request, 73–74registration code, testing, 100–102registration, implementing, 97–100rendering text, 73

request attributes, accessing, 68–70

Trang 11

Find it faste

request inputStream, reading, 89

request parameters, accessing, 73

running tests on, 12–13

User domain class, creating, 95–96

using messageSource bean in, 169

view

finding, selecting, and rendering, 76

security with JSecurity plugin, 431–432

withFormat method, 453–454, 459

ControllerUnitTestCase class, 91–93

Convention over Configuration

Custom Database Mapping DSL, 51

URL mapping and, 143

conventions, dynamic Spring beans using,

382–383

conversation scope (flows), 204, 206–208

converters, marshaling objects to XML with,

examples of, 353fields, 351special characters, 352cross-site scripting (XSS) attacksHTML escaping and, 409–411URL escaping and, 411–412CRUD (Create, Read, Update, Delete) applications

create operation, 21–23delete operation, 26read operation, 23–25scaffolding and, 17update operation, 25currencySelect tag, 122currentSession() method, 269Custom Database Mapping DSL, 51–53custom tags

basics of, 138–139creating, 136–137tab library, creating, 137–138testing, 139–141

custom view, selecting, 76customizing WAR file, 363

D

DAO (Data Access Object) layer, GORM and, 256

dataexporting to XML, 320–325

Trang 12

Errors API and, 79–80

file uploads and, 88–89

in flows, testing, 246–247

gTunes, 218–222

to multiple domain objects, 80

overview of, 77–78

validating incoming data, 78–79

data sources, configuring

DataSource.groovy file, 35–37

JNDI, 39

MySQL database, 37–39

overview of, 34

Data Transfer Object (DTO) pattern, 198

database identity generator, changing,

529–531database mapping, customizing, 51–53

database schemas, Hibernate and, 519

persisting fields to, 45–46

populating, with BootStrap classes,

364–365supported, 39–41

dataSource bean, overriding, 493

data-source definition, dialect property of, 41DataSource.groovy file

cache configuration, 283dialect setting, 264externalized configuration, 310hibernate block, 265

hibernate.cache.use_query_cache setting, 284

hibernate.flush.mode setting, 271logSql setting, 264

overview of, 35–37specifying annotation configuration strategy, 540

datePicker tag, 122–123dbCreate setting (development environment), 37DBMigrate plugin, 321debug levels, 307debugging remotely, with IDE, 344–345declarative syntax and HTTP method restrictions, 85–86

declaring classes, 548default action for controller, setting, 66–67default URL mapping, 143–144

default view, finding, 76default visibility, 548defaultCodec page directive, 411DefaultMessageListenerContainer class, 504defining

command objects, 82–83controllers

default action, setting, 66–67overview of, 65–66

flow action and view states, 202–203flow end state, 201–202

flow start state, 200–201flows, 200

jmsTemplate bean, 502music namespace, 190namespace for tag libraries, 138

Trang 13

user messages in properties file, 159–161

delete action (AlbumController), 29

versioning and metadata, 362–363

deployment to Tomcat, automating, 317–320

detached objects in GORM

dialect, configuring in GORM, 264–265

dialect setting (DataSource.groovy file), 264

disabling

See also enabling

auto time stamping, 288

“Buy” button, 439discovering plugins, commands for, 367–369display action (AlbumController), 181, 213displaying

album art, 182–193error message from command object, 234invoice, 240

progress indicator, 178displayInvoice.gsp end state view, 240distributing plugins, 389–390

documenting Gant scripts, 315–316domain classes

Address, 210–211Album, 23, 209AlbumPayment, 210building relationships between, 53–56with constraints, 166

constraints property, 46, 150creating, 17–19

custom validators, using, 49defining bidirectional one-to-many relationship, 24

defining one-to-many relationship between, 24

embedding objects, 59–60errors property, 48extending with inheritance, 56–58generating scaffolding for, 130–131interrelationships and, 23

Payment, 209Permission, 436–437persisting to database, 45, 46Post, 398

Role, 429–430saving, 267Song, 18–19, 444testing, 60–63

Trang 14

domain classes (continued)

transient properties of, 50–51

User, 95–96, 430, 535

validating, 46–49

domain model

See also domain classes

customizing database mapping, 51–53

object-oriented (OO) applications and, 45

domain objects

data binding to multiple, 80

embedding 59–60

mapping to relational databases, 45

updating with request parameters, 78

driver JAR file, adding to lib directory, 37

DTO (Data Transfer Object) pattern, 198

duck typing, 563

dynamic finders (GORM), 255–256

dynamic languages, and testing, 60

dynamic scaffolding, controllers and, 19–21

See also CRUD (Create, Read,

Update, Delete) applicationsdynamic Spring beans, 382–383

dynamic tags See tags, dynamic

dynamic transitions, gTunes application,

235–236dynamically creating beans, 497–498

running Grails project from, 341edit action (AlbumController), 29edit.gsp view, 33

effects, adding with Ajax, 193Ehcache caching solution, 187EJB 3-compliant mapping, 535–541Elvis operator (?:), 165

e-mail confirmation, sending, 348e-mail notifications, asynchronous, 511–513email property, 347

e-mail servers, integration with, 345–349embedded GStrings (GSP), 110–111embedding

objects, 59–60parameters in URL mapping, 145–147employee table, table-per-subclass mapping, 57

enabling

See also disabling

artist subscriptions, 505–510dynamic scaffolding, 20remote access to services, 300search, 195

encodeAsHTML() method, 411–414encodeAsURL() method, 412encoding data in GSP views to HTML, 411end states (flows), 201–202

enterCardDetails view state, 231–235enterShipping state, 218–222environments

DataSource.groovy file and, 35–36overview of, 33–34

production, 37–39environment-specific configuration, 306equals, implementing, 276–277

Trang 15

Find it faste

error codes, specifying custom, 49

error handling with tags

errors property (domain classes), 48

event handling, in Ajax, 178–179

events

GORM, 287–288

plugins and, 385–387

triggering

from action state, 203

from view state, 205–206

with return value, 203

exception types, org.jsecurity.authc package,

423

exceptions, logging, 68

executeQuery method, 262

executing

code before and after calls, 177–78

Grails under different environments, 34

execution, halting with before interceptor, 91

Expando object (Groovy), 555

Feeds plugin, 473–476fields, creating with tagscheckBox and radio tags, 120–121datePicker tag, 122–123

form tag, 119–120select tag, 121–122textField tag, 120file appenderconfiguring, 308using, 309file extensions, content negotiation with, 458file property (Song domain class), 444file uploads

data binding and, 88–89MultipartHttpServletRequest interface and, 87–88

overview of, 86filtering and iteration, tags forcollect tag, 114–115findAll tag, 115–116filters

implementing with JSecurity plugin, 427–429

overview of, 417–418findAll tag (GSP), 115–116findAllBy* method, 256findBy* method, 255–256Firefox

Poster pluginACCEPT header, specifying, 468installing, 467

main window, 467response window, 468tray icon, 467

RSS feeds, 476

Trang 16

action and view states, 202–203

defining, 200

end state, defining, 201–202

gTunes

credit card details, entering, 231–235

data binding and validation, 218–222

scopes, 204

start state, defining, 200–201

subflows and conversation scope, 206–208

testing, 244–247

transition actions and form validation, 206

view state, triggering events from, 205–206

flush() method, 266

flushing sessions

automatically, 270–272

manually, 267–268

for loop (Groovy), 557

form fields, enabling Ajax on, 193–197

form tag, 119–120

form validation, flows and, 206

format request parameter, using for content negotiation, 459

forms, creating with tagscheckBox and radio tags, 120–121datePicker tag, 122–123

form tag, 119–120select tag, 121–122textField tag, 120

404 response codes, custom mapping for, 154

Fowler, Martin, 545

G

g namespace, 138Gant, 6

Gant build systembootstrapping Grails from command line, 317

command-line variables, 313–314documenting scripts, 315–316overview of, 310–311

parsing command-line arguments, 314–315

reusing Grails scripts, 316scripts, creating, 312–313gant command, 311Gant scriptsautomating deployment to Tomcat, 317–320

creating, 312–313documenting, 315–316exporting data to XML, 320–325

<g:applyLayout> tag, 215

<g:createLink> tag, 475generate-controller command, 27generating

controller to implement CRUD functionality, 27–31views for actions to delegate to, 32–33genre action (StoreController), 128genre recommendations, querying for, 223

Trang 17

querying with criteria, 260

relationship management methods,

Hibernate library and, 18

listing, sorting, and counting, 250–251

automatic session flushing, 270–272clearing session, 269–270

Hibernate Session class, 266–267obtaining session, 268–269overview of, 265–266session management and flushing, 267–268

transactions in, 272–274

<g:paginate> tag, 263GPath expressionflow.albumPayments.album, 216interating with, 115

Grails

as platform, 3command-line interface, 6concepts embraced by, 1description of, 3

goal of, 1Groovy language and, 4–5installing, 5–6

simplicity and power of, 2welcome page, 13grails command, 34, 311grails console command, 455Grails context menu (TextMate), 343grails create-service command, 183grails create-taglib target, 137Grails stack, 2

grails war command, 362

Trang 18

eService.groovy, 290grails-app/taglib directory, 116

Meta Object Protocol, 384

mixing with Spring, 513–516

intercepting method dispatch, 565MetaClass, 562–563

overview of, 561–562overview of, 4–5, 545syntax

assertions, 548–549classes, declaring, 548closures, 552–553Expando object, 555lists and maps, 553–555overview of, 547–548ranges, 556–557strings, 549–552testing and, 60true object orientationmethods on primitives, 558–559operator overloading, 559–560overview of, 557–558

truth, 560–561

Groovy Server Pages See GSP

“Groovy Truth”, 216groovy.lang.Script class, 548GroovyPagesTestCase, 191GroovyShell class, 409GroovyTestCase API, extensions to, 245Groovy-WS project, 483–484

GSP (Groovy Server Pages)attributes, 108

basics of, 107–108built-in tagsfiltering and iteration, 114–116iterative, 113–114

logical, 112–113setting variables with, 111–112custom tags

basics of, 138–139

Trang 19

GSP code, extracting into templates, 214

GSP views, encoding data in, to HTML, 411

Ajax-powered features for, 173

album art, displaying, 182–193

Album domain class, 23

AlbumController, 24

albumList template, rendering, 132

artist subscriptions, enabling, 505–510

assertions, verifying flow state with,

credit card details, entering, 231–235data binding and validation, 218–222dynamic transitions, 235–236prices for albums, providing, 209purchase, 208

querying about CD purchase, 216–218recommendations, generating, 222–227recommendations, showing, 227–231validating login, 212–216

verifying flow state with assertions, 236–244

GSP templates for top five lists, 133home page

creating, 94–95

in English, 161

in Spanish, 163with login form, 97instance search box, 194jobs and, 356–361login form, adding, 96–97LoginCommand class, 102–104MonetaryAmount class, 526MonetaryAmountUserType, 526–528MUSICIAN_TO_RECORD join table, 524 “My Music” section, implementing, 433–446

paginating views in, 125–126plugins

album art service and tag library, 391–397

blog, 397, 406prices for albums, providing, 209purchase flow, 208

Trang 20

gTunes application (continued)

querying about CD purchase, 216–218

shop.gsp templates, rendering, 134

Song domain class, 18–19

tag library, creating for, 137

testing login process, 104–106

User domain class, 95–96

hasProperty method, 562hasRole method, 430HelloWorld.groovy script, 312–313help command, 6, 315

Hibernatedatabases supported by, 39–41description of, 2, 254

directory structure, 533features of, 519mapping withconstraints, using with POJO entities, 541–542

EJB 3-compliant, 535–541overview of, 532–535Session class, 266–267types, 524–529hibernate block (DataSource.groovy file), 265

Hibernate Criteria API, 257Hibernate library, 18Hibernate properties, configuring in GORM, 265

Hibernate Query Language (HQL), 261–262Hibernate Session, detached objects and, 274hibernate.cache.use_query_cache setting (DataSource.groovy file), 284hibernate.cfg.xml file, 532–533, 541hibernate.flush.Mode setting (DataSource.groovy file), 271

Trang 21

plugin descriptors and, 374–375

HQL (Hibernate Query Language), 261–262

“Build With Grails” build step, 334

configuring Grails installation in, 332

continuous integration with, 331–335

Dashboard, 331

free-style job, creating, 333

Grails build, configuring, 334

I

id column, 46

IDE (integrated development environment)

adding support to, 335–336

imperative approach to HTTP method restrictions, 85

import directive, 109importing Grails project into Eclipse, 339–341

index actionAlbumController, 28default, of controllers, 10inheritance

extending domain classes with, 56–58

in GORM, 285injecting jmsTemplate bean into class, 502

injecting services See dependency injection

in-memory database, 24inner beans, 495inputStream property (request object), 89installing

Grails, 5–6Java Management Extensions (JMX) plugin, 299

plugins, commands for, 369–370install-plugin command, 369install-plugin global command, 369

integrated development environment See

IDEintegration

See also Ant (Apache), integration with

with e-mail servers, 345–349integration tests, 11, 61IntelliJ (JetBrains), 336, 345Intercept, Cache, Invoke pattern, 566–567intercepting calls to methods, 90–91intercepting method dispatch, 565internationalization

See also localizing messages;

parameterized messages

Trang 22

internationalization (continued)

messageSource interface and, 168–170

URL mappings for, 163

validation messages and, 21

Inversion of Control (IoC) design pattern, 2,

289invoice, displaying, 240

invokeMethod method, overriding, 565

IoC (Inversion of Control), 2, 289

mixing with Spring, 513–516

Java Cryptography Extension, 414

Java Management Extensions (JMX) plugin,

299–304Java Monitoring and Management Console

(JConsole), 300–302Java Persistence API (JPA), 535

JAVA_OPTS environment variable, 300

JavaScript, calling REST web services from,

457–458JavaScript Object Notation (JSON)

marshaling objects to, 463–466

unmarshaling objects, 466–472

JConsole (Java Monitoring and Management Console), 300–302

JDBCdefining data sources and, 35metadata, 41

JetBrains IntelliJoverview of, 336remote debug configuration, 345JetGroovy plugin, 336

Jetty, 2

JMS API, Spring support for, 498 See also

ActiveMQJMS messagesconsuming with Spring, 503–505sending with Spring, 502–503JMX (Java Management Extensions) plugin, 299–304

JNDI data source, configuring, 39job template, 350

jobsadding and removing, 355–356gTunes and, 356–361

pausing and resuming, 355scheduling

cron, 351–353Quartz plugin, installing, 349–350scheduler, using, 354

simple, 350–351triggers and, 354–355triggering, 355

JodaTime API, 525joinTable mapping, 522JPA (Java Persistence API), 535

Trang 23

role-based security, implementing, 429–430

roles and permissions, 421

subjects and principals, 420

view, securing, 431–432

working with, 421

JSON (JavaScript Object Notation)

marshaling objects to, 463–466

legacy mapping with ORM DSL

association mapping, changing, 521–524

link discovery, Atom and RSS, 476–477link tag, 117–118, 154–155

linking tagscreateLink and createLinkTo, 118–119link, 117–118, 154–155

overview of, 117LiquiBase plugin, 321list action, 28, 412List associations, 253list() method, 250–251list.gsp view

for blog plugin, 399–401description of, 33listings

abstract beans, using, 495ACCEPT header, configuring additional MIME types, 453

ActiveMQ, starting, 499Address class

applying constraints to, 542defining, 210–211

Address.java class, 537AddressConstraints.groovy script, 542after interceptor, 91

afterView filter, 418Ajax login request, handling, 176Album class

creating, 23price property, 209album-art plugin exampleadding method to all controllers, 395–396

getArt() method and, 396mocking cacheService, 395providing metadata to, 393updating to use simple-cache plugin, 394

Trang 24

Artist show.gsp view, 455

_artist.gsp template, updating, 509

configuring using Config.groovy, 184defining, 491

beans property, 490before attribute, using, 178before interceptor

defining, 90halting execution with, 91belongsTo property, 54bindData method, 81binding XML data to new instances, 472blog plugin

adding metadata to, 397fckeditor plugin and, 402list.gsp view, 399–400Post domain class, 398PostController, 399_post.gsp template, 401URL mapping, 401Blowfish encryption codec class, 414–415BootStrap class, 364

build.xml file, running test target in, 325buyFlow, 240–244

cache policy, specifying, 283cache provider, specifying, 283

<cache:text> tag, 382caching

content-level, 382return value of blocks of code using closures, 381

caching pattern, 380car table, 59–60checkBox tag, 120checking whether user is subscribed, 507chooseGiftWrapFlow flow, 206–207

Trang 25

codec class example, 414

collecting values with <g:collect> tag, 114

column name for many-to-one

command-line arguments, handling, 315

Company class, transient property, 50

dynamically mapping to, 451

controller action vulnerable to attack

cron job, 352custom view, rendering, 76data binding, validation errors and, 79DataSource, specifying annotation configuration strategy, 540DataSource.groovy file, 36datePicker tag, 123debug level, setting, 307deep converter results, using, 461default Log4j configuration, 306default validation messages, 167DefaultMessageListenerContainer instance, configuring, 504delete action, 29

dependency injection, using to obtain Hibernate session, 269

dependsOn property, 394deploying to Tomcat, 319displayInvoice.gsp end state view, 240domain classes

with constraints, 166defining bidirectional one-to-many relationship, 24

defining one-to-many relationship between, 24

doWithSpring hook, 380, 393doWithWebDescriptor hook, adding Servlet filter with, 388

dynamic finders, 255dynamic querying with criteria, 258dynamic transitions, using to specify transition target state, 235dynamically configuring beans, 497dynamically creating beans, 498eager associations, 279–280edit action, 29

Ehcache Spring bean, configuring, 187

Ngày đăng: 13/08/2014, 08:21

TỪ KHÓA LIÊN QUAN