Format dates in show view

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Format dates in show view

Chris Malan
With the fields plugin things are a bit different.  I have /grails-app/views/_fields/date/_displayWrapper.gsp.  This file contains only this:
<%@ page defaultCodec="html" %>

<g:formatDate format="${constraints.format}" date="${value}" />

<%-- This works for the list view, but not the show view --%>

As the comment says, it works perfectly in the list/index view, but not the show view.  The format is supplied in the domain class constraints.  Getting the date pickers to render as I want them works perfectly with _widget.gsp.  I found what it needed on the web.  This is what it contains:
<%@ page defaultCodec="html" %>

<g:if test="${constraints.nullable == true}">
<g:datePicker name="${property}" value="${value}" precision="${constraints.attributes.precision}" years="${constraints.attributes.years}" default="none" noSelection="['': '']" />
</g:if>
<g:else>
<g:datePicker name="${property}" value="${value}" precision="${constraints.attributes.precision}" years="${constraints.attributes.years}"/>
</g:else>

Without the _displayWrapper.gsp the domain class constraint format doesn't work at all.  Any idea how to get the dates to show in the right format in the show view? 

Thanks.

Chris

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/f56519ac-651f-4844-a8eb-77968ff778f7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Format dates in show view

Chris Malan
OK, here it is.  It's a three step process.

First, in the domain class set the format in the constraints block like so:
toTheMinute nullable: false, format: 'dd MMM yyyy HH:mm'

Then create a file, _wrapper.gsp in grails-home/views/_fields/showDate  This showDate can be anything that takes your fancy.  This _wrapper.gsp looks like this:
 <li class="fieldcontain" style="list-style-type: none;">
<span class="property-label">${label}</span>
<div class="property-value">
<g:formatDate format="${constraints.format}" date="${value}" />
</div>
</li>

The last part is in the relevant show.gsp.  Here's what the relevant bit in mine looks like:
<ol class="property-list dates">
<f:with bean="dates">
<f:field property="toTheMinute" wrapper="showDate" />
<f:field property="toTheDay" wrapper="showDate" />
<f:field property="nullableDate" wrapper="showDate" />
<f:field property="dateCreated" wrapper="showDate" />
<f:field property="lastUpdated" wrapper="showDate" />
</f:with>
</ol>

This works.  Does anybody know of a way that doesn't need one specifying all fields in the domain class?

Chris Malan 

On Friday, February 12, 2016 at 9:44:52 AM UTC+11, Chris Malan wrote:
With the fields plugin things are a bit different.  I have /grails-app/views/_fields/date/_displayWrapper.gsp.  This file contains only this:
<%@ page defaultCodec="html" %>

<g:formatDate format="${constraints.format}" date="${value}" />

<%-- This works for the list view, but not the show view --%>

As the comment says, it works perfectly in the list/index view, but not the show view.  The format is supplied in the domain class constraints.  Getting the date pickers to render as I want them works perfectly with _widget.gsp.  I found what it needed on the web.  This is what it contains:
<%@ page defaultCodec="html" %>

<g:if test="${constraints.nullable == true}">
<g:datePicker name="${property}" value="${value}" precision="${constraints.attributes.precision}" years="${constraints.attributes.years}" default="none" noSelection="['': '']" />
</g:if>
<g:else>
<g:datePicker name="${property}" value="${value}" precision="${constraints.attributes.precision}" years="${constraints.attributes.years}"/>
</g:else>

Without the _displayWrapper.gsp the domain class constraint format doesn't work at all.  Any idea how to get the dates to show in the right format in the show view? 

Thanks.

Chris

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/9dacf4d8-5e76-4c06-b6a8-863ea7e47d6e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.