grails-3.1

Grails 3 "show" view with Fields plugin 2.1.0-SNAPSHOT


Stuck at a trivial problem in Grails 3.1.5: Show the fields of a domain object, excluding one of them, including a transient property. Yes, this is my first Grails 3 project after many years with previous versions.

The generated show.gsp contains

<f:display bean="rfaPdffile"/>

This will include a field that may contain megabytes of XML. It should never be shown interactively. The display: false constraint is no longer in the docs, and seems to be silenty ignored.

Next I tried explicitly naming the fields:

<f:with bean="rfaPdffile">
  <f:display property='fileName'/>
  <f:display property='pageCount'/>
  ...
</f:with>

This version suprisingly displays the values without any markup whatsoever. Changing display to field,

<f:with bean="rfaPdffile">
  <f:field property='fileName'/>
  <f:field property='pageCount'/>
  ...
</f:with>

sort of works, but shows editable values. So does f:all.

In addition I tried adding other attributes to f:display: properties (like in f:table), except (like in f:all). I note in passing that those two attributes have different syntax for similar purposes.

In the Field plugin docs my use case is explicitly mentioned as a design goal. I must have missed something obvious.

My aim is to quickly throw together a prototype gui, postponing the details until later. Clues are greatly appreciated


Solution

  • My own answer: "use the force, read the source". The f:display tag has two rather obvious bugs. I will submit a pull request as soon as I can.

    Bugs aside, the documentation does not mention that the plugin may pick up the "scaffold" static property from the domain, if it has one. Its value should be a map. Its "exclude" key may define a list of property names (List of String) to be excluded. This probably works already for the "f:all" tag; bug correction is needed for the "f:display" tag.

    My subjective impression is that the fields plugin is in a tight spot. It is intertwined with the Grails architecture, making it sensitive to changes in Grails internals. It is also required by the standard scaffolding plugin, making it very visible. Thus it needs constant attention from maintainers, a position not to be envied. Even now conventions for default constraints seem to have changed somewhere between Grails 3.0.9 and 3.1.7.

    Performance of the fields plugin is sensitive to the total number of plugins in the app where it is used. It searches all plugins dynamically for templates.

    For the wish list I would prefer stricter tag naming. The main tags should be verbs. There are two main actions, show and edit. For each action there are two main variants, single bean or multiple beans.