Grails下拉列表带有复合id
我需要为搜索功能填充一个下拉列表。我遇到了一些困难,因为表有一个复合id。我相信我必须引用两个外键,但不确定如何引用 Oracle 11g本地和只读 GG2.3.3 这是我使用复合密钥的域Grails下拉列表带有复合id,grails,composite-key,Grails,Composite Key,我需要为搜索功能填充一个下拉列表。我遇到了一些困难,因为表有一个复合id。我相信我必须引用两个外键,但不确定如何引用 Oracle 11g本地和只读 GG2.3.3 这是我使用复合密钥的域 static belongsTo = [trustee:Trustee, committees:Committees]// static constraints = { position nullable:true type nullable:tr
static belongsTo = [trustee:Trustee, committees:Committees]//
static constraints = {
position nullable:true
type nullable:true
}
static mapping = {
table 'BOT_TRUSTEE_COMMITTEES'
version false
id composite: ['trustee','committees']
trustee column:'TRUSTEE_ID'
committees column: 'COMMITTEE_ID'
position column:'POSITION'
type column:'TYPE'
}
下面是调用我的下拉列表的视图模板
<tr>
<td>
<label for="hospital">
<g:message code="hospitals.hospitalName.label" default="Hospital:" />
</label>
</td>
<td>
<g:select name="hospitalId" from="${Hospitals.list()}" optionKey="id" required="" optionValue="hospitalName" noSelection="['null':'-Choose a hospital-']"/>
</td>
</tr>
<!-- Committee drop down list -->
<tr>
<td>
<label for="committee">
<g:message code="committees.description.label" default="Committee:" />
</label>
</td>
<td>
<g:select name="committeesId" from="${Committees.list()}" optionKey="id" required="" optionValue="committeeName" noSelection="['null':'-Choose a committee-']" />
</td>
</tr>
<!-- Type drop down list -->
<tr>
<td>
<label for="type">
<g:message code="membership.type.label" default="Type:" />
</label>
</td>
<td>
<!-- input drop down list for type here -->
<g:select name="trusteeType" from="${TrusteeMembership.list()}" optionKey="id" required="" optionValue="type" noSelection="['null':'-Please select one-']"/>
</td>
</tr>
在上一个选项中,您有optionValue=type。。对吗?尝试将其重命名为trustName或其他名称,以防在某处键入某些保留字…键入的内容正确。我知道这可能是一个保留字。问题在于optionKey。请注意,此表使用的是复合键而不是主键。我输入了一个外键,它填充了列表,但是有几个重复。我该如何显示不同的值呢?是的,因为你似乎没有id,你在寻找它。。。。查找:要按id检索实例,请使用对象本身的原型:。也看看这里。因此,您可能需要提供您自己的hashMap列表,以便从上面的控制器访问,并设置您的自定义