grails脚手架配置(按域类)

grails脚手架配置(按域类),grails,scaffolding,Grails,Scaffolding,目前,我试图处理grails中的脚手架问题。在生成模板方面,我有一个小问题,我没有找到解决方案。我想在domainmodel中配置生成算法。 我的想法是在模型中定义静态变量,这些变量不是在数据库中创建的,只是对生成过程很重要。 例如,我只想在show.gsp中显示一些特殊字段,但我想在_form.gsp中显示每个字段,或者我想进行一些gsp导入,但只在单独的gsp中显示。 所以我想我可以定义一些静态变量,其中的值包含一些配置参数,我可以在生成模板中解释这些参数。 我希望大家都明白我的意思 以下是

目前,我试图处理grails中的脚手架问题。在生成模板方面,我有一个小问题,我没有找到解决方案。我想在domainmodel中配置生成算法。 我的想法是在模型中定义静态变量,这些变量不是在数据库中创建的,只是对生成过程很重要。 例如,我只想在show.gsp中显示一些特殊字段,但我想在_form.gsp中显示每个字段,或者我想进行一些gsp导入,但只在单独的gsp中显示。 所以我想我可以定义一些静态变量,其中的值包含一些配置参数,我可以在生成模板中解释这些参数。 我希望大家都明白我的意思

以下是一个例子:

class Awesome {
Long awesome_level
Long person_name
    Boolean itsMe

static String showFields 
static transients = ['showFields']

static constraints = {
    einrichtungs_type()
    type_of_conzept()
    anzahl_gruppen()
    anzahl_kinder_pro_Gruppe()
    offnungszeiten()
    showFields(["person_name", "itsMe"])
}
在Show视图中,我只想显示数组“showFields”中的字段

。。。
对于(道具中的p){
if(domainClass.showFields中的p.embedded&&p.name){
def embeddedPropNames=p.component.persistentProperties*.name
def embeddedProps=p.component.properties.findAll{embeddedPropNames.contains(it.name)&&!excludedrops.contains(it.name)}
Collections.sort(embeddedProps、comparator.constructors[0].newInstance([p.component]作为对象[])

%> 我找到了这个问题的解决方案。首先,我认为创建自定义约束是可能的。我仍然认为这也是可能的,但我找到了一种更好/更容易添加“配置”的方法。 我使用已经存在的标记属性。如果我理解正确,我用于在select Html标记中添加属性的属性参数。现在我使用它添加一些配置参数。我的解决方案如下:

  • 您必须更改“renderditor.template”,并不是所有配置参数都将添加HTMl标记作为属性。
    cp.attributes.each{k,v->
    某人
    某人
    
    ...
    for (p in props) {
        if (p.embedded && p.name in domainClass.showFields) {
            def embeddedPropNames = p.component.persistentProperties*.name
            def embeddedProps = p.component.properties.findAll { embeddedPropNames.contains(it.name) && !excludedProps.contains(it.name) }
            Collections.sort(embeddedProps, comparator.constructors[0].newInstance([p.component] as Object[]))
            %><fieldset class="embedded"><legend><g:message code="${domainClass.propertyName}.${p.name}.label" default="${p.naturalName}" /></legend><%
                for (ep in p.component.properties) {
                    renderFieldForProperty(ep, p.component, "${p.name}.")
                }
            %></fieldset><%
    
        } else {
            renderFieldForProperty(p, domainClass)
        }
    ...