[英]How to display Selected option Of timeZoneSelect Tag in grails
使用時區創建Customer時,timeZone具有值。 當我顯示timeZone時,我想顯示所選的選項。
例如,我想顯示SST,薩摩亞標准時間-11:0.0(選定選項),而不是Pacific / Midway(Value) 。
我必須在顯示頁面上對此功能進行哪些更改?
客戶類別{
static constraints = {
}
String name
String timeZone
}
在create.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>
在show.gsp中:
<span class="property-value" aria-labelledby="timeZone-label"><g:fieldValue bean="${customerInstance}" field="timeZone"/></span>
我找到了解決方案
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]
}
在Show.gsp中:
<span class="property-value" aria-labelledby="timeZone-label">${timeZone}</span>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.