2013-08-01 122 views
0

使用時區創建Customer時,timeZone具有該值。當我顯示時區時,我想顯示選定的選項。如何在grails中顯示timeZone選擇標籤的選項

例如,我想顯示SST,薩摩亞標準時間-11:0.0(當前選項)而非太平洋/中途(值)

我必須在此功能的顯示頁面中進行更改?

一流的客戶{

static constraints = { 
    } 
    String name 
    String timeZone 
} 

在create.gsp:

在show.gsp
<div class="fieldcontain ${hasErrors(bean: customerInstance, field: 'timeZone', 'error')} "> 
    <label for="timeZone"> 
     <g:message code="customer.timeZone.label" default="timeZone" /> 

    </label> 
    <g:if test="${customerInstance?.timeZone}"> 
     <g:timeZoneSelect name="timeZone" value="${TimeZone.getTimeZone(customerInstance?.timeZone)}" /> 
    </g:if> 
    <g:else> 
     <g:timeZoneSelect name="timeZone" value="${customerInstance?.timeZone}" /> 
    </g:else> 
</div> 

<span class="property-value" aria-labelledby="timeZone-label"><g:fieldValue bean="${customerInstance}" field="timeZone"/></span> 

回答

0

我已經找到了解決辦法

def show(Long id) { 
     def customerInstance = Customer.get(id) 
     if (!customerInstance) { 
      flash.message = message(code: 'default.not.found.message', args: [message(code: 'customer.label', default: 'Customer'), id]) 
      redirect(action: "list") 
      return 
     } 

     def date = new Date() 
     TimeZone tz = TimeZone.getTimeZone(customerInstance.timeZone); 
     def shortName = tz.getDisplayName(tz.inDaylightTime(date), TimeZone.SHORT); 
     def longName = tz.getDisplayName(tz.inDaylightTime(date), TimeZone.LONG); 
     def offset = tz.rawOffset; 
     def hour = offset/(60 * 60 * 1000); 
     def min = Math.abs(offset/(60 * 1000)) % 60; 
     def timeZone= shortName+", "+longName+" "+hour+": "+min 
     [customerInstance: customerInstance,timeZone:timeZone] 
    } 

In Show.gsp:

<span class="property-value" aria-labelledby="timeZone-label">${timeZone}</span>