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

  • Home
  • SEARCH
  • 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 8795359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:22:34+00:00 2026-06-13T23:22:34+00:00

I am currently working on a Grails application and I am looking place a

  • 0

I am currently working on a Grails application and I am looking place a select list on the page and have its Key set to one value and the Value set to another. The code of all related elements is below:

Domain Object:

class Cars {
  String carType
  String car
}

Controller:

def create() {
  List cars = Cars.list()
  [dealerInstance: new Dealer(params), cars: cars]
  render(text:"This site in curently under Maintainence!")
}

View:

<g:select name="cars.id" from="${cars}" optionKey="${carType}" optionValue="${car}"/>

Now when I run this code the list does get populated however data looks like below:

<select id="cars.id" name="cars.id">
  <option value="com.app.Cars : 1">com.app.Cars : 1</option>
  <option value="com.app.Cars : 2">com.app.Cars : 2</option>
  <option value="com.app.Cars : 3">com.app.Cars : 3</option>
</select>

and then when I try this:

View:

<g:select name="cars.id" from="${cars.car}" optionKey="${carType}" optionValue="${car}"/>

I get the following:

<select id="cars.id" name="cars.id">
  <option value="Audi">Audi</option>
  <option value="BMW">BMW</option>
  <option value="Scoda">Scoda</option>
</select>

This is not what I want at all I want to be able to set a different Key Value pair on this select list so that I can use that data within my application, I would want the following to be generated:

<select id="cars.id" name="cars.id">
  <option value="Saloon">Audi</option>
  <option value="Hatch Back">BMW</option>
  <option value="Estate">Scoda</option>
</select>

Can someone please tell me how I achieve this within Grails???

  • 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-13T23:22:34+00:00Added an answer on June 13, 2026 at 11:22 pm

    Try this:

    <g:select id="cars.id" name="cars.id" from="${cars}" optionKey="carType" optionValue="car"/>
    

    What basically happens:

    When you use the from attribute, the tag iterates over the list you passed as an argument. optionKey and optionValue should be strings representing the attributes you want to access in the current object (being accessed by the iterator).

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

Sidebar

Related Questions

I am currently working on grails project. I have created eight different plugins. Each
I am currently developing a Grails Application and I am working with the Spring
I’m working on a grails web application with spring security. I have a requirement
We have an application in Grails 2.0 that we have working when we run
I'm currently working with Grails 1.3.7, and I have the following domain classes connected
On one of the edit views of my Grails application I have several chained
I have been working on the project where application is using grails 1.2.2.... Now
I am now currently working on a grails project . I have a problem
I am currently working on a grails project where I need to execute a
I'm currently working on a project using netbeans 6.9 and grails 1.3. I'm trying

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.