30
Published under the Creative Commons Attribution Noncommercial Share Alike License Version 2.5. (Please see http://creativecommons.org/licenses/by-nc-sa/2.5 for complete details.) Going Further with Grails Jason Rudolph [email protected]

Going Further with Grails - jasonrudolph.comCustom tags Named (and found by Grails) using convention Names end with "TagLib" (e.g., RacetrackTagLib.groovy) Located in grails-app/taglib

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Going Further with Grails - jasonrudolph.comCustom tags Named (and found by Grails) using convention Names end with "TagLib" (e.g., RacetrackTagLib.groovy) Located in grails-app/taglib

Published under the Creative Commons Attribution Noncommercial Share Alike License Version 2.5. (Please see http://creativecommons.org/licenses/by-nc-sa/2.5 for complete details.)

Going Further with Grails

Jason [email protected]

Page 2: Going Further with Grails - jasonrudolph.comCustom tags Named (and found by Grails) using convention Names end with "TagLib" (e.g., RacetrackTagLib.groovy) Located in grails-app/taglib

Introduction

Jason Rudolph

jasonrudolph.com

thinkrelevance.com

Page 3: Going Further with Grails - jasonrudolph.comCustom tags Named (and found by Grails) using convention Names end with "TagLib" (e.g., RacetrackTagLib.groovy) Located in grails-app/taglib

Agenda

Beyond scaffolding

When the UI and the DB disagree

DRY UI

Business logic, right where it belongs

Calling in the Java infantry

Security? Just plug it in

Page 4: Going Further with Grails - jasonrudolph.comCustom tags Named (and found by Grails) using convention Names end with "TagLib" (e.g., RacetrackTagLib.groovy) Located in grails-app/taglib

scaffolding.next()Demo

Page 5: Going Further with Grails - jasonrudolph.comCustom tags Named (and found by Grails) using convention Names end with "TagLib" (e.g., RacetrackTagLib.groovy) Located in grails-app/taglib

Tag Libraries

Pre-packaged tags

Logical - if, else, etc.

Iterative - while, each, findAll, etc.

Form - textField, checkBox, datePicker, etc.

Rendering - layoutBody, paginate, etc.

Ajax - remoteField, submitToRemote, etc.

And others...

Page 6: Going Further with Grails - jasonrudolph.comCustom tags Named (and found by Grails) using convention Names end with "TagLib" (e.g., RacetrackTagLib.groovy) Located in grails-app/taglib

Tag Libraries (cont’d)Custom tags

Named (and found by Grails) using convention

Names end with "TagLib" (e.g., RacetrackTagLib.groovy)

Located in grails-app/taglib

Implemented as closures

No TLDs necessary

User-contributed tags

Page 7: Going Further with Grails - jasonrudolph.comCustom tags Named (and found by Grails) using convention Names end with "TagLib" (e.g., RacetrackTagLib.groovy) Located in grails-app/taglib

Command & ConquerDemo

Page 8: Going Further with Grails - jasonrudolph.comCustom tags Named (and found by Grails) using convention Names end with "TagLib" (e.g., RacetrackTagLib.groovy) Located in grails-app/taglib

Command Objects

Why?

Business objects minus persistence, or

View-centric adaption of the domain

Auto-populated from request params

Play nicely with constraints

At home in src/groovy, grails-app/controllers, or directly inside the controller

Page 9: Going Further with Grails - jasonrudolph.comCustom tags Named (and found by Grails) using convention Names end with "TagLib" (e.g., RacetrackTagLib.groovy) Located in grails-app/taglib

“Flash” Cards

Page 10: Going Further with Grails - jasonrudolph.comCustom tags Named (and found by Grails) using convention Names end with "TagLib" (e.g., RacetrackTagLib.groovy) Located in grails-app/taglib

redirect_after_post == good

Page 11: Going Further with Grails - jasonrudolph.comCustom tags Named (and found by Grails) using convention Names end with "TagLib" (e.g., RacetrackTagLib.groovy) Located in grails-app/taglib

!manual_session_cleanup

Page 12: Going Further with Grails - jasonrudolph.comCustom tags Named (and found by Grails) using convention Names end with "TagLib" (e.g., RacetrackTagLib.groovy) Located in grails-app/taglib

request < flash < session

Page 13: Going Further with Grails - jasonrudolph.comCustom tags Named (and found by Grails) using convention Names end with "TagLib" (e.g., RacetrackTagLib.groovy) Located in grails-app/taglib

flash.lifetime == request.lifetime++

Page 14: Going Further with Grails - jasonrudolph.comCustom tags Named (and found by Grails) using convention Names end with "TagLib" (e.g., RacetrackTagLib.groovy) Located in grails-app/taglib

Talking BackDemo

Page 15: Going Further with Grails - jasonrudolph.comCustom tags Named (and found by Grails) using convention Names end with "TagLib" (e.g., RacetrackTagLib.groovy) Located in grails-app/taglib

LayoutsPowered by SiteMesh

A home for common site assets

Menus, headers, footers

Global CSS and JavaScript

Global metadata

Precedence rules

Explicitly declared layouts

Layout by convention

Page 16: Going Further with Grails - jasonrudolph.comCustom tags Named (and found by Grails) using convention Names end with "TagLib" (e.g., RacetrackTagLib.groovy) Located in grails-app/taglib

Where’s My Layout?

1. Is it declared in the view?

<meta name="layout" content="foo" />

2. Fallback to convention. Layout for this view?

/views/layouts/sponsorship/create.gsp

3. Layout for this controller?

/views/layouts/sponsorship.gsp

4. Punt!

Rendering views/sponsorship/create.gsp ...

Page 17: Going Further with Grails - jasonrudolph.comCustom tags Named (and found by Grails) using convention Names end with "TagLib" (e.g., RacetrackTagLib.groovy) Located in grails-app/taglib

Partial Templates

Why? DRY UI!

Naming

Locating

Passing variables

bean

collection

hash

Page 18: Going Further with Grails - jasonrudolph.comCustom tags Named (and found by Grails) using convention Names end with "TagLib" (e.g., RacetrackTagLib.groovy) Located in grails-app/taglib

It’s All Relative

<!-- ... --><g:render template="foo"><!-- ... -->

views/sponsorship/create.gsp

Page 19: Going Further with Grails - jasonrudolph.comCustom tags Named (and found by Grails) using convention Names end with "TagLib" (e.g., RacetrackTagLib.groovy) Located in grails-app/taglib

From the Top

<!-- ... --><g:render template="/shared/foo"><!-- ... -->

views/sponsorship/create.gsp

Page 20: Going Further with Grails - jasonrudolph.comCustom tags Named (and found by Grails) using convention Names end with "TagLib" (e.g., RacetrackTagLib.groovy) Located in grails-app/taglib

Partial Templates

Why? DRY UI!

Naming

Locating

Passing variables

bean

collection

hash

Page 21: Going Further with Grails - jasonrudolph.comCustom tags Named (and found by Grails) using convention Names end with "TagLib" (e.g., RacetrackTagLib.groovy) Located in grails-app/taglib

At Your ServiceDemo

Page 22: Going Further with Grails - jasonrudolph.comCustom tags Named (and found by Grails) using convention Names end with "TagLib" (e.g., RacetrackTagLib.groovy) Located in grails-app/taglib

Services

Declarative transactionality

Flexible scoping

Zero-configuration dependency injection

Page 23: Going Further with Grails - jasonrudolph.comCustom tags Named (and found by Grails) using convention Names end with "TagLib" (e.g., RacetrackTagLib.groovy) Located in grails-app/taglib

Calling All JARsDemo

Page 24: Going Further with Grails - jasonrudolph.comCustom tags Named (and found by Grails) using convention Names end with "TagLib" (e.g., RacetrackTagLib.groovy) Located in grails-app/taglib

Security

Authenticate

Authorize

Administer

http://www.flickr.com/photos/amagill/235453953/Used under Creative Commons Attribution 2.0 Generic License (http://creativecommons.org/licenses/by/2.0/deed.en-us)

Page 25: Going Further with Grails - jasonrudolph.comCustom tags Named (and found by Grails) using convention Names end with "TagLib" (e.g., RacetrackTagLib.groovy) Located in grails-app/taglib

Acegi Plugin

User account management

Password encryption

Log in & log out interface

Role management

Resource management

Hide/show UI elements based on user roles

Registration e-mails

Page 26: Going Further with Grails - jasonrudolph.comCustom tags Named (and found by Grails) using convention Names end with "TagLib" (e.g., RacetrackTagLib.groovy) Located in grails-app/taglib

Lock-downDemo

Page 27: Going Further with Grails - jasonrudolph.comCustom tags Named (and found by Grails) using convention Names end with "TagLib" (e.g., RacetrackTagLib.groovy) Located in grails-app/taglib

Whew!

It ain’t just scaffolding

The UI and the DB needn’t always agree

Banishing UI redundancy

Thin controllers, fat services

Java at your fingertips

Plug in and go

Page 28: Going Further with Grails - jasonrudolph.comCustom tags Named (and found by Grails) using convention Names end with "TagLib" (e.g., RacetrackTagLib.groovy) Located in grails-app/taglib

Resources

grails.org

Downloads

Latest Release (1.0.1)

Development Snapshot (1.0.2)

User guide, tutorials, screencasts, etc.

Mailing lists (grails.org/mailing+lists)

Page 29: Going Further with Grails - jasonrudolph.comCustom tags Named (and found by Grails) using convention Names end with "TagLib" (e.g., RacetrackTagLib.groovy) Located in grails-app/taglib
Page 30: Going Further with Grails - jasonrudolph.comCustom tags Named (and found by Grails) using convention Names end with "TagLib" (e.g., RacetrackTagLib.groovy) Located in grails-app/taglib

Slides & Examples Available

@

jasonrudolph.com/downloads

Please Fill Out Your Evaluations

This presentation is published under the Creative Commons Attribution Noncommercial Share Alike License Version 2.5.

(Please see http://creativecommons.org/licenses/by-nc-sa/2.5 for complete details.)