Upload
to-the-new-technology
View
79
Download
0
Embed Size (px)
Citation preview
Data Bindingin 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
Introduction to AWS CodeDeploy
• Single domain class form• Multiple instances of a domain
class• Associations• A domain object with file
Single Domain Class
def save = {def b = new Book()b.properties = paramsb.save()
}
Single Domain Class
def save = {def b = new Book(params) b.save()
}
def update = {def b = Book.get(params.id) b.properties = paramsb.save()
}
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")
BindData examples
// exclude firstName and lastName and only useparameters starting with "author." e.g. author.emailbindData(target, this.params, ['firstName', 'lastName'], "author")
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}
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'])
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>
Addressing Security Concerns
Use Special Command Objects Use “excludes” parameter
References / Attribution
DGG – Second Edition – Chapter 4http://grails.org/Controllers+-+Data+Binding
License
This work is licensed under the Creative Commons Attribution-Non-commercial-Share Alike 3.0 License
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