views:

39

answers:

2

In my view I have the following:

<g:hiddenField name='expandableEducationList[${edIdx}]._deleted' value='false'/>
<button 
                onclick="dojo.byId('expandableEducationList[${edIdx}]._deleted').value='true'; getContainer(this, 'tr').style.display='none'"
                style="width:auto;"
                iconClass="minusIconSmall"
                showlabel="false"
                class="embedded"            
                dojoType="dijit.form.Button"></button>

How do I get that expandableEducationList from my controller? If I do a "println params" I can see the values there, but I want to iterate over the list and params.expandableEducationList is returning null

Here's what I get in my controller when I print the values:

    params?.each{
        println ("it: " + it)
    }

returns

it: expandableEducationList[2].type.id=35
it: expandableEducationList[2]=["lastModified_day":"29", "id":"272", "lastModified_year":"2010", "areaOfStudy":"Computer
 Science", "yearGranted":"2008", "lastModified_month":"9", "_deleted":"false", "_inProcess":"", "type":["id":"35"], "col
legeName":"COLLEGE3", "type.id":"35"]
it: expandableEducationList[1]._deleted=false
it: expandableEducationList[1]=["id":"271", "lastModified_day":"29", "lastModified_year":"2010", "areaOfStudy":"Mathemat
ics and Computer Science", "yearGranted":"2009", "lastModified_month":"9", "_inProcess":"", "_deleted":"false", "type":[
"id":"30"], "type.id":"30", "collegeName":"COLLEGE1"]
it: expandableEducationList[2].id=272
it: _action_update=
it: expandableEducationList[1].lastModified_month=9
it: expandableEducationList[2].yearGranted=2008
it: expandableEducationList[1].collegeName=COLLEGE1
it: id=518
it: _expandableEducationList[2].inProcess=
it: expandableEducationListx[0]_name=42
it: expandableEducationList[0].areaOfStudy=Systems Engineering
it: expandableEducationList[0]=["lastModified_day":"29", "id":"270", "lastModified_year":"2010", "yearGranted":"2010", "
areaOfStudy":"Systems Engineering", "lastModified_month":"9", "_deleted":"false", "_inProcess":"", "type":["id":"42"], "
type.id":"42", "collegeName":"COLLEGE2"]
it: expandableEducationList[2].lastModified_day=29
it: expandableEducationList[0].id=270
it: expandableEducationList[2]._deleted=false
it: expandableEducationList[0].lastModified_day=29
it: geographicPreferences=
it: expandableEducationList[2].areaOfStudy=Computer Science
it: expandableEducationList[2].collegeName=COLLEGE3
it: expandableEducationListx[1]_name=30
it: expandableEducationList[1].lastModified_day=29
it: _expandableEducationList[0].inProcess=
it: _expandableEducationList[1].inProcess=
it: expandableEducationList[0]._deleted=false
it: expandableEducationList[1].yearGranted=2009
it: expandableEducationList[1].lastModified_year=2010
it: expandableEducationList[2].lastModified_month=9
it: expandableEducationList[1].areaOfStudy=Mathematics and Computer Science
it: expandableEducationList[2].lastModified_year=2010
it: expandableEducationList[1].id=271
it: expandableEducationListx[2]_name=35
it: expandableEducationList[0].yearGranted=2010
it: expandableEducationList[0].lastModified_month=9
it: expandableEducationList[0].collegeName=COLLEGE2
it: expandableEducationList[0].lastModified_year=2010
it: expandableEducationList[0].type.id=42
it: expandableEducationList[1].type.id=30
A: 

pass it in as part of the model in your controller action that is rendering the gsp

like this...

[expandableEducationList: ExpandableEducation.list()]

or something like this..

  render(view: 'viewName', 
         model: [expandableEducationList: ExpandableEducation.list()])
Aaron Saunders
Actually, I think he's going the other way with it - he wants to know how he can get it in the controller after the form has been submitted.
Rob Hruska
What Rob said is correct. When I do params.each{ println it } I can defitely see all the values..will update what it shows
Derek
Sorry.. I misunderstood
Aaron Saunders
I must be missing something silly, but it seems like params.expandableEducationList shouldnt be null..there is a definitely a field for each of the 3 items in the list there
Derek
It does seem like if I used params['expandableEducationList[1]'] I can get the parameters for that first one, but thats kind of a clunky way of going about it. Guess I could make a loop and check for null?
Derek
why do you say it is null?
Aaron Saunders
what does this dump out params?.expandableEducationList?.each{ println ("it: " + it) }
Aaron Saunders
A: 

The "Grailsy" way to do this is to use Command objects and Data Binding. Look at Data Binding and Many-ended Associations here.

With that, you could create a Command object that maps to your association and then bind the request parameters using something like:

def command = new MyCommand()
bindData(command, params)

This is just an alternative solution to the one you mentioned in the comments on Aaron's answer.

Rob Hruska