【问题标题】:Format month name of <rich:calendar> as MMM instead of MMMM将 <rich:calendar> 的月份名称格式化为 MMM 而不是 MMMM
【发布时间】:2016-04-19 11:47:54
【问题描述】:

如何将 &lt;rich:calender&gt; 显示的月份从“April”更改为 3 个字符的“Apr”?

【问题讨论】:

    标签: jsf calendar richfaces date-format


    【解决方案1】:

    不支持,如果要更改它,则需要覆盖创建元素的 JavaScript 方法,如下所示:

    var calendar = #{rich:component('calendar')};
    var fn = calendar.calendarContext.currentMonthControl;
    
    calendar.calendarContext.currentMonthControl = function(context) {
        var newDate = RichFaces.calendarUtils.formatDate(context.calendar.getCurrentDate(), "MMM, yyyy", context.monthLabels, context.monthLabelsShort);
        var markup = fn(context);
        markup.childs[0].value = newDate;
        return markup;
    }
    

    当然,您必须确保在重新呈现日历时也会重新呈现此代码。


    大部分日历代码是在客户端创建的。 (注意:这是内部的东西,你不应该知道它是如何工作的)。

    calendar.calendarContext.currentMonthControl负责创建标签,它返回这个对象:

    {
        "tag":"div",
        "attrs":{
            /* event listeners, unimportant */
        },
        "childs":
            [{"value":"April, 2016"}]
    }
    

    您所做的是将原始方法替换为修改此对象的新方法。 RichFaces.calendarUtils.formatDate 在原函数中以“MMMM, yyyy”模式调用,所以我们用不同的模式调用它,然后调用原函数,替换文本,返回修改后的对象。

    【讨论】:

    • 你能解释一下代码,就像它在做什么,非常抱歉,RichFaces 是新手
    • 编辑了答案,但如果您是 RichFaces 的新手,我不建议您弄乱代码。
    猜你喜欢
    • 2020-02-29
    • 2015-05-25
    • 2017-02-20
    • 1970-01-01
    • 1970-01-01
    • 2011-03-13
    • 1970-01-01
    • 2013-12-19
    • 1970-01-01
    相关资源
    最近更新 更多