Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9136301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:56:06+00:00 2026-06-17T08:56:06+00:00

Using Grails and the scenario is if I have an object passed in from

  • 0

Using Grails and the scenario is if I have an object passed in from an HTTP request and I iterate through the object and grab all possible objects as in:

if (params.colors) {
  for (String color in params.colors) {
    println color
  }
}

If a [Ljava.lang.String is passed in (i.e., params.colors = [“blue”,”green”,”yellow”]) then your output is as expected:

blue
green
yellow

But if params.colors = “blue”, then of course, groovy will tokenize “blue” and you’ll get the output:

b
l
u
e

I suppose I should be checking to see if it’s already an array. Unless I’m approaching this wrong or there is a groovy way of doing it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:56:06+00:00Added an answer on June 17, 2026 at 8:56 am

    You can access the colors param as a list using the list method on the params object:

    for (String color in params.list('colors')) {
      println color
    }
    

    This way, it won’t matter if you action is called like /your_action?colors=red or /your_action?colors=red&colors=green or even with no colors param at all (that’s why i left out the if), params.list('colors') will always return a list 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Grails 2.0.1 (upgraded from 1.3.7). In application.properties I have app.context = / and
Using Grails database-migration I have a table in production defined like so: +--------------+------------+------+-----+---------+----------------+ |
I'm considering using Grails for my current project. I have a couple of requirements
I am using Grails Webflow, what ever object I pass to a view, it
I'm using Grails 1.3.7 and the db-migration plug-in. I have generated a chagelog.groovy-file containing
Using Grails and CXF, I have published a small web service that looks like
I am using grails 1.3.7. I have a Config.groovy file that specifies a number
I am using Grails 2.1.0 and lesscss-resources 1.3.0.3 I have created a plugin containing
We are using grails-groovy with Hibernate, I have a SQL query like this in
We're developing an app (using Grails Spring Security (formerly Acegi)) in which we'll have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.