how to bind/update Whole InstanceList in Controller ?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

how to bind/update Whole InstanceList in Controller ?

0 down vote favorite

I am new bie in grails and i have following query.

Problem Domain:

 1-Parent Domain Class has a boolean transient property "isValid".
 2-Child Domain has a boolean property "isValid".
 3-Parent/list.gsp allow users to alter isValid property of Parent Instance in ParentInstanceList, over an update function in ParentController, which i can further use to set each Parents children's property "isValid".

Parent Domain Class

class Parent {

String name
boolean isValid = false

static hasMany = [children:Child]
static transients =['isValid']


Child Domain Class

class Child {

String name
boolean isValid
Parent parent

static belongsTo = [parent:Parent]



    <g:form method="post" action="update" >
    <div class="list">
                    <g:sortableColumn property="id" title="${message(code: '', default: 'Id')}" />

                    <g:sortableColumn property="name" title="${message(code: '', default: 'Name')}" />
                     <g:sortableColumn property="isValid" title="${message(code: 'parent.isvalid.label', default: 'isValid?')}" />

                                                    <g:hiddenField name="parentInstanceList" value="${parentInstanceList }"/>
            <g:each in="${parentInstanceList}" status="i" var="parentInstance">

<g:link action="show" id="${}">${fieldValue(bean: parentInstance, field: "id")}</g:link>${fieldValue(bean: parentInstance, field: "name")}                    <g:checkBox name="isValid" value="${parentInstance?.isValid }"/>
    <div class="paginateButtons">
        <g:paginate total="${parentInstanceTotal}" />

    <div class="buttons">
            <g:actionSubmit class="update" action="update" value="${message(code: 'default.button.update.label', default: 'update')}" />

<a href="http://">Parent/list.gsp snapshot

Query: how can i track down which parentInstance's property "isValid" is not checked/unchecked that i can easily set parent's children property "isvalid" .

def parentInstanceList  = params.parentInstanceList
    parentInstanceList.each {
        Parent parent = it
            Child child = it

So far i am able to retrieve ids of all parents over params.parentInstanceList but i can not figure it out how can i bind changed properties of each parentInstance. if there is a single parentInstance then one can easily do it

Parent parentInstance = Parent.get( = params

thanks in advance