开发者

Is there any JSF Select Time Zone component out there?

I have b开发者_如何学Pythoneen looking for this for a while and haven't found it. It is surprisingly complicated as shown in this old IceFaces tutorial.

What is needed is a UIInput component that will set a java.util.TimeZone property, allowing the user to select it from a map or a list on the screen. Before I dive in to write one for myself -- does anyone know of an available component that does this?


Use <h:selectOneMenu> to represent a dropdown list. Use <f:selectItems> to feed it with a E[], List<E>, SelectItem[] or List<SelectItem> as value.

Here's how it can look like at its simplest:

@ManagedBean
@ViewScoped
public class Bean implements Serializable {

    private String timeZoneID; // +getter +setter
    private String[] timeZoneIDs; // +getter only

    @PostConstruct
    public void init() {
        timeZoneIDs = TimeZone.getAvailableIDs();
        // You may want to store it in an application scoped bean instead.
    }

    public void submit() {
        System.out.println("Selected time zone: " + TimeZone.getTimeZone(timeZoneID));
    }

    // ...
}

with this view:

<h:form>
    <h:selectOneMenu value="#{bean.timeZoneID}" required="true">
        <f:selectItem itemValue="#{null}" itemLabel="Select timezone..." />
        <f:selectItems value="#{bean.timeZoneIDs}" />
    </h:selectOneMenu>
    <h:commandButton value="submit" action="#{bean.submit}" />
    <h:messages/>
</h:form>

If you want to make it a fullworthy TimeZone property, you'd need to bring in a @FacesConverter(forClass=TimeZone.class) which should be pretty straightforward enough.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜