15

Data Binding in Grails

Embed Size (px)

Citation preview

Page 1: Data Binding in Grails
Page 2: Data Binding in Grails

Data Bindingin Grails

Page 3: Data Binding in Grails

Agenda

1. What is data binding?

2. What are the possible scenarios?

3. What options does Grails provides for data binding?

4. Security concerns

Page 4: Data Binding in Grails

Introduction to AWS CodeDeploy

• Single domain class form• Multiple instances of a domain

class• Associations• A domain object with file

Page 5: Data Binding in Grails

Single Domain Class

def save = {def b = new Book()b.properties = paramsb.save()

}

Page 6: Data Binding in Grails

Single Domain Class

def save = {def b = new Book(params) b.save()

}

def update = {def b = Book.get(params.id) b.properties = paramsb.save()

}

Page 7: Data Binding in Grails

BindData examples

// request parameters to a target objectbindData(target, this.params)

// exclude firstName and lastNamebindData(target, this.params,['firstName', 'lastName'])

// only use parameters starting with "author." e.g. author.emailbindData(target, this.params, "author")

Page 8: Data Binding in Grails

BindData examples

// exclude firstName and lastName and only useparameters starting with "author." e.g. author.emailbindData(target, this.params, ['firstName', 'lastName'], "author")

Page 9: Data Binding in Grails

Binding with Associations

class SomeCO{Date startDate; Date endDate;Project project

}<g:datePicker name="startDate"/><g:datePicker name="startDate"/><g:select name="project.id" from="${someList}" value="${project?.name}" optionKey="id"/>

def myAction{SomeCOsomeCO ->// perform action}

Page 10: Data Binding in Grails

Binding with Associations

class Book{String name Author author

}

<input type="text" name="book.name"<input type="text" name="author.name"

class Author{String name

}

def b = new Book(params['book'])def a = new Author(params['author'])

Page 11: Data Binding in Grails

Binding with Associations

<g:form action=”save”>Title:<input type=”text” name=”album.title” /> <br>Artist:<input type=”text” name=”artist.name” /><br>Song 1:<input type=”text” name=”songs[0].name”/><br> Song 2:<input type=”text” name=”songs[1].name”/><br> Song 3:<input type=”text” name=”songs[3].name”/><br>

</g:form>

Page 12: Data Binding in Grails

Addressing Security Concerns

Use Special Command Objects Use “excludes” parameter

Page 13: Data Binding in Grails

References / Attribution

DGG – Second Edition – Chapter 4http://grails.org/Controllers+-+Data+Binding

Page 14: Data Binding in Grails

License

This work is licensed under the Creative Commons Attribution-Non-commercial-Share Alike 3.0 License

Page 15: Data Binding in Grails

Contact us

Our Office

Client Location

Here's how the world's biggest Grails team is building enterprise applications on Grails!Click Here To Know More!

Have more queries on Grails? Talk to our GRAILS experts Now!

Talk To Our Experts