grails scaffolding configuration by domainclass -


at moment try deal scaffolding in grails. there have little problem generation-templates don't find solution. want configure generating-algorithm in domainmodel. thought define static variables in model aren't created in database , important generation-process. example want display special fields in show.gsp want display every field in _form.gsp or want gsp-imports in seperate gsp. thought define static variables value contains configuration-parameter can interpretate in generation template. hope understand mean ?

here 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 show-view want display fields in array "showfields"

... (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] object[]))         %><fieldset class="embedded"><legend><g:message code="${domainclass.propertyname}.${p.name}.label" default="${p.naturalname}" /></legend><%             (ep in p.component.properties) {                 renderfieldforproperty(ep, p.component, "${p.name}.")             }         %></fieldset><%      } else {         renderfieldforproperty(p, domainclass)     } ... 

i know if clause don't work. problem is, not able value of field "showfields". know questions:

  • is able receive values of field of domainclass?
  • is able execute methode of domainclass?
  • is there other way define configuration-parameters can access in generation-templates?

i hope able display problem , thank help! greetz v

i found solution problem. first of thought possible creation of custom-constraint. still thinking possible found better /easyer way add "configurations". use tag attributes, exsits. if understand right, attributes parameter used add attributes in select-html-tags. use adding configuration-parameters. here solution:

  1. you have change "rendereditor.template" not configuration-parameter add in html-tag attribute. cp.attributes.each { k, v -> sb << "${k}=\"${v}\" " } change cp.attributes?.realattributes.each { k, v -> sb << "${k}=\"${v}\" " }
  2. when realy want attributes-function add attributes-parameter value "realattributes" (or how call it)
  3. change constraints of model: (in example:)

static constraints = { einrichtungs_type(attributes: [showfield:true]) }

  1. finaly change generation-template

if(cp.attributes?.showfield){ ...

i hope these 4 steps you, if have same problems.

greetz

v


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -