Data Binding in Grails
Agenda 1. What is data binding? 2. What arethe possible scenarios? 3. What options does Grails provides for data binding? 4. Security concerns
Introduction to AWS CodeDeploy • Single domain classform • Multiple instances of a domain class • Associations • A domain object with file
Single Domain Class def save={ def b =new Book() b.properties =params b.save() }
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() }
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")
BindData examples // exclude firstName and lastName and only use parameters starting with "author." e.g. author.email bindData(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{SomeCO someCO -> // 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{ Stringname } 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 –Chapter4 http://grails.org/Controllers+-+Data+Binding
License Thiswork islicensed under the Creative Commons Attribution-Non-commercial-Share Alike 3.0License
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

Data Binding in Grails

  • 2.
  • 3.
    Agenda 1. What isdata binding? 2. What arethe possible scenarios? 3. What options does Grails provides for data binding? 4. Security concerns
  • 4.
    Introduction to AWSCodeDeploy • Single domain classform • Multiple instances of a domain class • Associations • A domain object with file
  • 5.
    Single Domain Class defsave={ def b =new Book() b.properties =params b.save() }
  • 6.
    Single Domain Class defsave={ def b =new Book(params) b.save() } def update ={ def b =Book.get(params.id) b.properties =params b.save() }
  • 7.
    BindData examples // requestparameters 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 // excludefirstName and lastName and only use parameters starting with "author." e.g. author.email bindData(target,this.params,['firstName','lastName'], "author")
  • 9.
    Binding with Associations classSomeCO{ 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 classBook{ 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:formaction=”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>
  • 12.
    Addressing Security Concerns UseSpecial Command Objects Use “excludes” parameter
  • 13.
    References / Attribution DGG–Second Edition –Chapter4 http://grails.org/Controllers+-+Data+Binding
  • 14.
    License Thiswork islicensed underthe Creative Commons Attribution-Non-commercial-Share Alike 3.0License
  • 15.
    Contact us Our Office Client Location Here'show 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