Brian
Brian

Reputation: 173

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

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!

Upvotes: 7

Views: 15117

Answers (3)

DKanavikar
DKanavikar

Reputation: 31

Why not use g:countrySelect tag? This will save One whole Domain.

Upvotes: 3

Benoit Wickramarachi
Benoit Wickramarachi

Reputation: 6226

Use the select tag structure provided by mpccolorado, then to have Canada selected by default change the value to:

value="2"

(the Id for Canada).

Upvotes: 1

mpccolorado
mpccolorado

Reputation: 827

Use the value attribute to set the selected item:

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

Upvotes: 9

Related Questions