views:

62

answers:

1

I am wanting to use the g:timeZoneSelect tag within my application, problem is im finding the resulting html select to be quite overwhelming.

  1. Over 600 options are being displayed, IMHO this is to much to display to the user. Maybe someone could point me to an example of a much more manageable list of timezones? Maybe you have seen a site that does timezone selection well? Im sure over 600 option is "technically" correct, but this will just look like noise to the user.

  2. The display value of the timezone is to long.

E.g. "CST, Central Standard Time (South Australia/New South Wales) 9.5:30.0"

Just "CST, Central Standard Time" or "Australia/Broken_Hill" would be better

Is there a way to address these issues via tag attributes of some sort (cant find any in the docs) or config that I am unaware of?

Or, is my best bet to wrap an html select within a custom tag lib and "roll my own" solution (Id prefer not to).

Thanks

+1  A: 

Having a look at the source, there's no way to override the "optionValue" attribute, as it is set in the taglib method itself

So I guess you'd have to roll your own :-(

The source for the original tag is here, which should be a good starting point. You'd probably need something like this:

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)
    }
}

Then you could do:

<my:tzSelect/>
tim_yates