This tutorial is about Data Binding in Grails. The tutorial includes an introduction to data binding, the possible scenarios while data binding, options that Grails provides for data binding and security concerns during data binding. The tutorial begins with a section that provides an introduction to data binding in grails and also includes multiple instances and associations.
The next section is about possible scenarios which are data binding examples like requesting parameters, excluding names, only using parameters or both. Followed is a section which gives a brief about the options that Grails provides for data binding. It talks about options/associations that Grails provide and codes for binding using associations.
The last section of this tutorial gives details of the security concerns that should take place while data binding. It involves addressing security concerns like using commands and parameters, it even involves a license.
6. Single Domain Class
def save={
def b =new Book(params)
b.save()
}
def update ={
def b =Book.get(params.id)
b.properties =params
b.save()
}
7. BindData examples
// request parameters to a target object
bindData(target,this.params)
// exclude firstName and lastName
bindData(target,this.params,['firstName', 'lastName'])
// only use parameters starting with"author." e.g.
author.email
bindData(target,this.params, "author")
8. BindData examples
// exclude firstName and lastName and only use
parameters starting with "author." e.g. author.email
bindData(target,this.params,['firstName','lastName'],
"author")
9. 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{SomeCO
someCO ->
// perform action
}
10. Binding with Associations
class Book{
String name
Author author
}
<input type="text" name="book.name"
<input type="text" name="author.name"
class Author{
Stringname
}
def b =new Book(params['book'])
def a =new Author(params['author'])
11. 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>
15. 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