Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 227
Brian Avatar asked Jan 18 '13 12:01

Brian


2 Answers

Use the value attribute to set the selected item:

<g:select name="user.company.id"
from="${Company.list()}"
value="${user?.company.id}"
optionKey="id" />
like image 142
mpccolorado Avatar answered Nov 12 '22 23:11

mpccolorado


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

like image 38
DKanavikar Avatar answered Nov 12 '22 23:11

DKanavikar