How to set selected value when using g:select in grails

Brian picture Brian · Jan 18, 2013 · Viewed 14k times · Source

I'm newbie with Grails framwork. I have issue:

I have Domain is: "Country". And I wants to show list country in select tag by using g:select in Grails

For example: The data store in database can see below

ID             Name

1              England
2              Canada
3              Germany

Now, I wants set "Canada" is selected. Who can help me. Please!

Answer

mpccolorado picture mpccolorado · Jan 18, 2013

Use the value attribute to set the selected item:

<g:select name="user.company.id"
from="${Company.list()}"
value="${user?.company.id}"
optionKey="id" />