Grails f:field 显示选定的下拉列表

Grails f:field display selected dropdown

您好,我是 Grails 的新手,我在 Grails 中有一个非常简单的问题,我希望有人能帮助我。

我有一个简单的域class 人如下:

class Person {

    String  name    //  name of the person
    Date    dob     //  date of birth

}   // end of class

我的数据库中已经有一些 Person 条目。

在另一种形式中,我想让用户 select 从下拉列表中选择年龄在 21 岁以上的人的名字。现在看起来像这样:

<fieldset class="form">

    <f:field bean="Person" property="name" />

</fieldset>

如何从数据库中筛选出所有其他人,只显示 21 岁以上的人的名字?

在此先感谢您!

在controller中搜索大于21岁的人,然后传给gsp显示。像这样:

import groovy.time.TimeCategory

def create() {

// all your other codes
def adults = Person.findAllByDobGreaterThanEquals(new Date() - 21.year) 

// other codes....
respond new Person(params), model:[adults :adults]
}

然后将其与结果集一起显示在gsp中。

<fieldset class="form">

    <f:field bean="Person" property="name" >
        <g:select name="name" from="${adults}" optionKey="id" />
    </f:field>

</fieldset>