Posted by: nerdgerl on: August 20, 2009
A fairly common requirement is to populate values in a select box/drop down box with values from a database. It’s quick and easy to do in Grails.
def search = {
def authors = Book.executeQuery("SELECT distinct b.author FROM Book b")
[authors : authors]
}
<g:select id="authorSelection" name="author" from="${authors}" value="" noSelection="['':'Please Select...']> params.author
EDIT: I recently found an official looking tutorial about how to do selects with grails here.
How about really long lists… How do I handle that…
Let’s say,
I am making a Book. Each book as 1 Author, and a Title.
I have an Author with a first and last name.
Each book, has 1 author, and in the drop down list, you choose the Author you want.
Now Imagine, I have 100 Author entries….
How do I handle the long list of authors?
September 7, 2009 at 12:59 pm
Thanks, didn’t use executeQuery but used the principle
,
saw your lvl80 DK as well , pick a good class next time :p
September 8, 2009 at 6:36 am
Hey Paul. Thanks for visiting my site. You sure you don’t have me mixed up with someone else… I have a level 80 lock.. horde of course, no DK’s for me