Reputation: 177
at the moment I try to deal with scaffolding in grails. There I have a little problem with the generation-templates where i don't find a solution. I want to configure the generating-algorithm in the domainmodel. My thought was to define static variables in the model which aren't created in the database and only important for the generation-process. For example I want to display only some special fields in the show.gsp but i want to display every field in the _form.gsp Or i want to do some gsp-imports but only in seperate gsp. So i thought that i could define some static variables where the value contains some configuration-parameter i can interpretate in the generation template. I hope everybody understand what I mean ?
Here is an example:
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"])
}
In the Show-View i only want to display the fields in the array "showFields"
...
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)
}
...
I know that the if clause don't work. My problem is, that i am not able to get the value of the field "showFields". Know my questions:
I hope i was able to display my problem and thank you for some help! Greetz V
Upvotes: 0
Views: 208
Reputation: 177
I found a solution for that problem. First of all I thought it could be possible with the creation of a custom-Constraint. I am still thinking that this is also possible but i found a better /easyer way to add "configurations". I use the tag attributes, which already exsits. If i understand it right, the attributes parameter i used to add attributes in select-Html-tags. Now i use it for adding some configuration-parameters. Here my solution:
cp.attributes.each { k, v ->
sb << "${k}=\"${v}\" "
}
change to cp.attributes?.realAttributes.each { k, v ->
sb << "${k}=\"${v}\" "
}
static constraints = { einrichtungs_type(attributes: [showField:true]) }
if(cp.attributes?.showField){ ...
I hope these 4 steps help you, if you have nearly the same problems.
Greetz
V
Upvotes: 0