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 ?

rehman
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]

}

parent/list.gsp

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

                    <g:sortableColumn property="name" title="${message(code: 'parent.name.label', 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:each>
                   
<g:link action="show" id="${parentInstance.id}">${fieldValue(bean: parentInstance, field: "id")}</g:link>${fieldValue(bean: parentInstance, field: "name")}                    <g:checkBox name="isValid" value="${parentInstance?.isValid }"/>
                   
    </div>
    <div class="paginateButtons">
        <g:paginate total="${parentInstanceTotal}" />
    </div>

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

<a href="http:// http://img156.imageshack.us/i/parentlistview.png/">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
        parent.children.each{
            Child child = it
            child.isValid=parent.isValid
        }
    }

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.id)
 parentInstance.properties = params

thanks in advance

Rehman