Grails 3 with Fields plugin - show fields like numbers and dates in certain format

170 views Asked by At

A Book domain object has a publicationYear field. In the show view it shows as 2,011 or 1,999 or whatever. It should display as 2011. It used to be a simple g:fomatNumber to get things right.

According to the Fields documentation at http://grails-fields-plugin.github.io/grails-fields/guide/customizingFieldRendering.html one should create a directory grails-app/views/controllerName/actionName/propertyName/ and put a _wrapper.gsp template in it. They don't say what should be in that file. I've tried various things and it looks as if it is just ignored. The year is still 2,013 or whatever.

This will mainly be needed to display dates in various ways - mostly day or minute precision. In this case I want to get rid of the comma.

Any idea how to do this? I'm using Grails 3.0.9 and Scaffolding 3.1.3 because anything newer does not install templates and if one hand installs them, ignores them.

1

There are 1 answers

0
D.Ivanov On

If I understood you correctly the publicationYear property is of type Date?
In this case you can use the tag

g:formatDate

to display it.
So if you only need the year:

g:formatDate format="yyyy" date="${publicationYear}"

See: Grails 3.0.9 formatDate
Hope it helps