extract values from params having array as key.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

extract values from params having array as key.

Mauro
After submitting a form params are:

phones[0].number:12212, phones[0]:[number:12212], referenceNumber:, phones[1].number:wwefeww, phones[1]:[number:wwefeww]

I need to extract the values from phones.
Trying something like params.phones.collect { it.number} does not work.
How can I do?
Reply | Threaded
Open this post in threaded view
|

Re: extract values from params having array as key.

Mauro
any advice?


On 27 December 2013 00:15, Mauro Sanna <[hidden email]> wrote:
After submitting a form params are:

phones[0].number:12212, phones[0]:[number:12212], referenceNumber:, phones[1].number:wwefeww, phones[1]:[number:wwefeww]

I need to extract the values from phones.
Trying something like params.phones.collect { it.number} does not work.
How can I do?

Reply | Threaded
Open this post in threaded view
|

Re: extract values from params having array as key.

Jeff Scott Brown-2
In reply to this post by Mauro


On December 26, 2013 at 5:17:37 PM, Mauro Sanna ([hidden email]) wrote:

>  
> After submitting a form params are:
>  
> phones[0].number:12212, phones[0]:[number:12212], referenceNumber:,  
> phones[1].number:wwefeww, phones[1]:[number:wwefeww]  
>  
> I need to extract the values from phones.
> Trying something like params.phones.collect { it.number}  
> does not work.
> How can I do?
>  

There isn’t enough info in the question to say for sure what your best options are.  One thing you could do is let the framework do it for you.  If you have request parameters like those described below you could submit that request to an action that has a command object that looks something like this:


class SomeController {

    def processPhones(PhonePool phonePool) {
        // …
    }
}

class PhonePool {
    List<Phone> phones
}

class Phone {
    String number
}



JSB

Jeff Scott Brown
[hidden email]

Autism Strikes 1 in 166  
Find The Cause ~ Find The Cure
http://www.autismspeaks.org/



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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: extract values from params having array as key.

SAgrawal14
Try: params.list("phone")*.number

Shashank


On Sun, Dec 29, 2013 at 8:00 AM, Jeff Scott Brown <[hidden email]> wrote:


On December 26, 2013 at 5:17:37 PM, Mauro Sanna ([hidden email]) wrote:
>
> After submitting a form params are:
>
> phones[0].number:12212, phones[0]:[number:12212], referenceNumber:,
> phones[1].number:wwefeww, phones[1]:[number:wwefeww]
>
> I need to extract the values from phones.
> Trying something like params.phones.collect { it.number}
> does not work.
> How can I do?
>

There isn’t enough info in the question to say for sure what your best options are.  One thing you could do is let the framework do it for you.  If you have request parameters like those described below you could submit that request to an action that has a command object that looks something like this:


class SomeController {

    def processPhones(PhonePool phonePool) {
        // …
    }
}

class PhonePool {
    List<Phone> phones
}

class Phone {
    String number
}



JSB

Jeff Scott Brown
[hidden email]

Autism Strikes 1 in 166
Find The Cause ~ Find The Cure
http://www.autismspeaks.org/



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

    http://xircles.codehaus.org/manage_email



Thank You,

SA
Reply | Threaded
Open this post in threaded view
|

Re: extract values from params having array as key.

Mauro

On 29 December 2013 06:35, Shashank Agrawal <[hidden email]> wrote:
Try: params.list("phone")*.number


it gives an empty array.
Reply | Threaded
Open this post in threaded view
|

Re: extract values from params having array as key.

SAgrawal14
Oh, Its typo. That should be params.list("phones") instead of params.list("phone")

Shashank


On Sun, Dec 29, 2013 at 6:01 PM, Mauro Sanna <[hidden email]> wrote:

On 29 December 2013 06:35, Shashank Agrawal <[hidden email]> wrote:
Try: params.list("phone")*.number


it gives an empty array.

Thank You,

SA
Reply | Threaded
Open this post in threaded view
|

Re: extract values from params having array as key.

Mauro

On 31 December 2013 08:35, Shashank Agrawal <[hidden email]> wrote:
Oh, Its typo. That should be params.list("phones") instead of params.list("phone")



Yes I've tries using "phones" but the same, it gives me an empty list.