我想在我的应用程序中使用g:timeZoneSelect标记,问题是im发现最终的html选择非常强大。
例如。科技委中央标准时间(南澳大利亚/新南威尔士)9.5:30.0
只要"CST,中央标准时间“或”澳大利亚/破碎山“就更好了
有没有办法通过某种标记属性(在文档中找不到任何标记属性)或配置来解决这些问题?
或者,我最好的选择是将html select封装在一个自定义标记库中,并“滚动我自己的”解决方案(Id不喜欢)。
谢谢
发布于 2010-05-28 07:32:46
查看源代码,就无法覆盖"optionValue“属性,因为它是在taglib方法本身中设置的。
所以我想你得自己滚-
原始标记的源在这里。应该是一个很好的起点。你可能需要这样的东西:
class MyNewTagLib {
static namespace = 'my'
def tzSelect = { attrs ->
attrs['from'] = TimeZone.getAvailableIDs();
attrs['value'] = (attrs['value'] ? attrs['value'].ID : TimeZone.getDefault().ID)
def date = new Date()
// set the option value as a closure that formats the TimeZone for display
attrs['optionValue'] = {
TimeZone tz = TimeZone.getTimeZone(it);
def shortName = tz.getDisplayName(tz.inDaylightTime(date), TimeZone.SHORT);
def longName = tz.getDisplayName(tz.inDaylightTime(date), TimeZone.LONG);
return "${shortName}/${longName}"
}
// use generic select
out << g.select(attrs)
}
}然后你就可以:
<my:tzSelect/>https://stackoverflow.com/questions/2927162
复制相似问题