0

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

sodastream
  • 129
  • 10

3 Answers3

0

If I understood you correctly, you want to have all bean properties included in the gsp but the one with the "megabytes of XML" should not be displayed to the user? If that is the case you can do:

f:with bean="beanName" 
f:field property="firstPropertyName"
f:field property="secondPropertyName"

And the one you don't wish to display:

g:hiddenField name="propertyName" value="${beanName.propertyName?}"
f:with

So list all the properties as f:field or f:display and put the one you don't wish to display in a g:hiddenField Grails tag You can also try:

f:field property="propertyName" 
widget-hidden="true"

but the Label is not hidden in this case. Hope it helps

Smittey
  • 2,475
  • 10
  • 28
  • 35
D.Ivanov
  • 11
  • 4
  • Sorry, but this is the "show" view, values should not be editable. "f:field" makes them editable. – sodastream May 19 '16 at 08:15
  • That's why I wrote "list all properties as `f:field` or `f:display`". More as a generall approach, in your case you should use display for the properties you wish to display and wrap the one you do not in a `g:hiddenField` – D.Ivanov May 19 '16 at 08:44
  • Sorry, the question already contains code snippets to illustrate that (inside "f:with"), "f:display" outputs text without markup (completely useless in my opinion), "f:field" generates editable fields. Please suggest something new. In a "show" view there is no point in generating hidden fields for omitted properties. – sodastream May 22 '16 at 19:41
0

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.

sodastream
  • 129
  • 10
0

My answer is that at present (2 March 2017) there is no answer. I have searched the Net high and low. For the index (list) and create and edit views, the fields plugin works well enough. A certain field can be easily excluded from the create and edit views, relatively easily from the list view (by listing those that should show), and in no way I could find from the show view. This is such a common need that one would suspect it will be addressed soon. Also, easily showing derived values in the show view, like 'total' for an invoice. One can do that by adding an ordered list with a list item showing the value below the generated ordered list of values, but that is kind of a hack.

In some ways, the old way was easier. Yes, it generated long views, but they were generated and didn't have to be done by the programmer - just custom touches here and there.

Chris Malan
  • 127
  • 1
  • 8