我正在尝试使用fields插件修改field脚手架代码。我还安装了twitter bootstrap。现在,我想在一行中显示2个字段。我在_form.gsp模板文件中做了以下操作:
private renderFieldForProperty(p, owningClass,counter, prefix = "") {
boolean hasHibernate = pluginManager?.hasGrailsPlugin('hibernate')
boolean display = true
boolean required = false
if (hasHibernate) {
cp = owningClass.constrainedProperties[p.name]
display = (cp ? cp.display : true)
required = (cp ? !(cp.propertyType in [boolean, Boolean]) && !cp.nullable && (cp.propertyType != String || !cp.blank) : false)
}
if (display) {
if(counter%2==0){
%><div class="row-fluid"><%
}
%>
<f:field bean="${domainClass.propertyName}" property="${p.name}"/>
<%
counter++
if(counter%2==0){
%></div><%
}
} } %>
现在生成的代码如下:
<div class="row-fluid">
<f:field bean="patient" property="familyName"/>
<f:field bean="patient" property="firstName"/>
</div>
当我尝试在浏览器中查看代码时,出现以下异常:
URI
/patient/create
Class
org.springframework.beans.NotReadablePropertyException
Message
Invalid property 'familyName' of bean class [java.lang.String]: Bean property 'familyName' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
我想我做错了对吗?我该如何解决?
谢谢,
费拉斯
最佳答案
似乎字段标记无法解析“耐心的” bean。根据您的脚手架模型,您可能需要在“${}
”中加上“Patient”(您的bean),或者在页面中定义一个名为“Patient”的变量。
关于grails - 使用字段插件修改Grails脚手架模板时发生异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13598453/