Does the Struts2 DateTimePicker allow to input dat

2019-02-20 19:08发布

Does the Struts2 DateTimePicker have support for specifying different Locales and Timezones?

I presume that it takes into account the Locale specified by the request, but I don't see that specifically mentioned anywhere in the documentation.

Nor I see it indicating any support for Timezones.

1条回答
欢心
2楼-- · 2019-02-20 20:06

This is a broad topic, but I'll try to reduce the few things I know:

  • The short answer is no, Struts2 integrated Dojo DateTimePicker doesn't allow you to do that.
    If you really need to support TimeZones (and not Locales), for example:

    an American user, travelling with its US-Locale laptop in India, wants to insert a datetime with the Tokyo TimeZone into your Web Application.

    Both its laptop's Locale nor your server nor his ISP informations would suffice, then you need something custom, like the:

    Any+Time™ DatePicker/TimePicker AJAX Calendar Widget

    enter image description here

    Because this is not a common use-case, and hence you probably need to fork off the main road.
    That said, there is some consideration worth noting when speaking of the Struts2 Dojo tags, Struts2 jQuery plugin, HTML5 and datetimepickers in general:

  • Many Struts2 Dojo tags have been deprecated long time ago. Those tags were based on old / buggy versions of Dojo, not aligned to the current release and hence potentially problematic. Appearently, Struts2 Dojo DateTimePicker is still alive, but I'd suggest not using it.

  • There is instead a Struts2 jQuery plugin, actively maintained, and based on a pretty new version of jQuery. It has a DateTimePicker that, even if with some bug, can be used comfortably. Otherwise, consider using raw jQuery and the DateTimePicker Plugin.

  • Nowadays it is important (mainly to support mobile browsing) to always use the native HTML5 <input type="date"/> and <input type="datetime-local" />, with a fallback for the (many) cases where the native HTML5 widget is not supported yet (eg. Firefox, IE, etc). There is a small difference in classic browsing (apart form the fact that the HTML5 widget opens a calendar without using javascript, and hence it works in browsers with javascript disabled), but there is a HUGE difference in mobile browsing, because when you have a small, high-resolution screen and only the fingers to tap, getting a small jQuery calendar or getting the following widget, changes the user-experience a lot:

    enter image description here

Summarizing: no Struts-Dojo, yes jQuery, but only if HTML5 date/time is not available.

That said, neither Dojo, jQuery nor HTML5 solutions include TimeZone data.

There is a variant of the HTML5 datetime with Locale (but no TimeZone) information, <input type="datetime-local" />, but the support for datetime and datetime-local is scarce today, and you can't rely on it, yet.

This because they're still working drafts, not standards, so the fallback is mandatory (even if your users are forced to use a single browser that today supports them).

Try it in this demo, with Chrome for example, to check how it works and how it is rendered. This for example is how it was displayed on Opera:

enter image description here

Just my 2 cents on a hugely evolving field.

查看更多
登录 后发表回答