【问题标题】:DatePicker from Wicket jQuery UI ignores pattern and locale来自 Wicket jQuery UI 的 DatePicker 忽略模式和语言环境
【发布时间】:2016-08-24 11:26:00
【问题描述】:

我需要在 Wicket 中的 jQuery UI DatePicker 上设置我自己的日期模式和语言环境。问题是 DatePicker 似乎忽略了所有设置。这是我的代码:

dateField = new DatePicker("dateField", new ComponentPropertyModel<>(id), "d.M.yyyy", new Options());

System.out.println("locale: " + dateField.getLocale());
System.out.println("format: " + dateField.getTextFormat());

add(dateField);

stdout 中的输出看起来很有希望:

locale: cs
format: d.M.yyyy

但仍然在页面上,我只看到英语语言环境和完全不同的日期格式。

是我做错了什么,还是 Wicket 的 jQuery UI 中存在错误?我该如何解决?

提前致谢!

【问题讨论】:

    标签: javascript java jquery-ui datepicker wicket


    【解决方案1】:

    今天终于通过关注How do I localize the jQuery UI Datepicker?解决了这个问题。

    您只需从https://github.com/jquery/jquery-ui 下载jQuery UI,然后将ui/i18n 中的文件复制到您的项目中。

    然后你需要在你的 HTML 标记中使用正确的 JS 文件,所以你可以这样解决它:

    public void renderHead(IHeaderResponse response) {
        try {
            String locale = datePicker.getLocale().toString();
            String path = "scripts/datepicker/datepicker-" + locale + ".js";
    
            response.render(JavaScriptHeaderItem.forUrl(path));
        }
        catch (Exception e) {
            // ignored at this moment
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-07
      • 2019-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-26
      • 1970-01-01
      相关资源
      最近更新 更多