【发布时间】:2013-11-24 06:46:58
【问题描述】:
我是grails 的初学者,我有一个基本问题。我想在子类表单创建中显示父类的实例列表。
My Domain 类如下。 Parent 类是 Company。
class Company {
String name
static constraints = {
name(blank:false)
}
String toString(){name}
}
我的子类是公司的位置。
class Location {
String name
String address
static belongsTo= {companyLocation:Company}
static constraints = {
name(blank: false)
address blank:false
}
String toString(){"company:"+companyLocation+"Location:"+name}
}
现在在_form template' of location view I have the code for thecompanyLocation 下拉菜单中`
<div class="fieldcontain ${hasErrors(bean: locationInstance, field: 'companyLocation', 'error')} required">
<label for="companyLocation">
<g:message code="location.companyLocation.label" default="companyLocation" />
<span class="required-indicator">*</span>
<g:select id="companyLocation" name="companyLocation.id" from="${first_project.Company.list()}" optionKey="id" required="" value="${locationInstance?.companyLocation?.id}" class="many-to-one"/>
</label>
</div>
当我进入创建页面时出现错误:
Error 500: Internal Server Error
URI /first_project/location/create
Class groovy.lang.MissingPropertyException
Message No such property: companyLocation for class: first_project.Location
当我在 Location Domain 类中定义了静态变量 companyLocation 时,为什么会出现此错误?有人可以告诉我哪里出错了吗?
提前致谢。
【问题讨论】:
标签: grails grails-2.0 gsp