Quantcast

Grails 1.3.7 - Attempting to create multiple records from a single request

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Grails 1.3.7 - Attempting to create multiple records from a single request

gcarbone
All,

I've been searching for hours without success.  Any help would be appreciated.

I have a gsp that allows the person to select a user and multiple roles (user and role are both domains).

I want to create multiple userrole entries (also a domain) with all of the user/role combinations in the request params.

Contrary to most of my searching, regardless if one or multiple roles are selected and are returned as a string.

If there is a single role selection, everything looks OK (eg. "1"), but if there are multiple selected the returned string looks like this: "[1,2]".

I've tried params.list("role"), params.role.values() and a number of other fruitless ways to get it so that I can loop over each of the role entries, such as:

def selectedroles = params.list("role")
selectedroles.each({ r ->
                        println "role id=" + r + " type is "+ r.getClass().name
                })

Any guidance would be appreciated.

Regards,

Gene
Regards,

Gene
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Grails 1.3.7 - Attempting to create multiple records from a single request

Gaurav Chauhan-2
Put this as first line inside your action:

params.role = params.role instanceof String ? [params.role] : params.role

params.role.each{
//Your code goes here..............
}

Hope it helps.

Regards
Gaurav Chauhan



On Tue, Nov 15, 2011 at 11:17 PM, gcarbone <[hidden email]> wrote:
All,

I've been searching for hours without success.  Any help would be
appreciated.

I have a gsp that allows the person to select a user and multiple roles
(user and role are both domains).

I want to create multiple userrole entries (also a domain) with all of the
user/role combinations in the request params.

Contrary to most of my searching, regardless if one or multiple roles are
selected and are returned as a string.

If there is a single role selection, everything looks OK (eg. "1"), but if
there are multiple selected the returned string looks like this: "[1,2]".

I've tried params.list("role"), params.role.values() and a number of other
fruitless ways to get it so that I can loop over each of the role entries,
such as:

def selectedroles = params.list("role")
selectedroles.each({ r ->
                       println "role id=" + r + " type is "+ r.getClass().name
               })

Any guidance would be appreciated.

Regards,

Gene

--
View this message in context: http://grails.1312388.n4.nabble.com/Grails-1-3-7-Attempting-to-create-multiple-records-from-a-single-request-tp4073428p4073428.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Grails 1.3.7 - Attempting to create multiple records from a single request

gcarbone
This was the perfect answer to my problem.


Thank you for your response!
Regards,

Gene
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Grails 1.3.7 - Attempting to create multiple records from a single request

Gaurav Chauhan-2
Glad it helped :-)

Regards
Gaurav Chauhan



On Wed, Nov 16, 2011 at 7:58 PM, gcarbone <[hidden email]> wrote:
This was the perfect answer to my problem.


Thank you for your response!

-----
Regards,

Gene
--
View this message in context: http://grails.1312388.n4.nabble.com/Grails-1-3-7-Attempting-to-create-multiple-records-from-a-single-request-tp4073428p4076472.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Loading...