如何设置primefaces时钟小部件的开始时间? [英] How to set start time for primefaces clock widget?

查看:106
本文介绍了如何设置primefaces时钟小部件的开始时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以设置PrimeFaces时钟小部件的开始时间? 我从PrimeFaces Extensions了解模拟时钟,但是我需要具有此选项的数字时钟. 我已经尝试为此时钟改写javascript方法,但是它不起作用.

Is it possible to set start time for PrimeFaces clock widget? I know about Analog Clock from PrimeFaces Extensions, but I need digital clock with this option. I have tried to override javascript method for this clock, but it doesn't work.

  PrimeFaces.widget.Clock = PrimeFaces.widget.BaseWidget.extend({

    init: function(cfg) {
        this._super(cfg);

        this.cfg.value = 1430304817141;
        this.current = this.isClient() ? new Date() : new Date(this.cfg.value);
        var $this = this;

    },

    isClient: function() {
        return this.cfg.mode === 'client';
    },

});

推荐答案

第一个问题是,在PrimeFaces实例化其原始未修改的窗口小部件之后,您太晚重写窗口小部件了.根据 PrimeFaces可自定义资源排序,覆盖的正确位置将在h:head中.
第二个问题是您要使用残废的版本覆盖小部件,该版本不包含原始小部件中存在的许多必要功能.

The first problem was that you were overriding the widget too late, after PrimeFaces has instantiated its original unmodified widget. According to PrimeFaces Customizable Resource Ordering the right place to override would be in h:head.
The second problem is that you're overriding the widget with a crippled version, that doesn't contain many necessary functions that were present in the original widget.

我根本不会推荐这种方法-基本上是这样破坏整个PrimeFaces小部件的.如果您想使用正常的不变时钟怎么办?复制粘贴的代码也更难以维护.我建议采用更本地化的方法:仅调整单个小部件实例.

I wouldn't recommend this approach at all - to basically break the whole PrimeFaces widget like that. What if you'd want to use the normal unchanged clock? Copy-pasted code is harder to maintain too. I advise going the more localized approach: tweak only a single widget instance.

<p:clock id="my_clock" />
<script>
    // get widgetVar via EL function, since p:clock doesn't have the widgetVar attribute
    var myClockVar = #{p:widgetVar('my_clock')};
    myClockVar.current = new Date(1430304817141);
</script>

请小心不要用AJAX请求更新时钟,否则它将重置为显示客户端时间.而不更新脚本,否则时钟将再次重置为指定时间.

Just be careful not to update the clock with AJAX requests, or it will to reset to showing client time; and not to update the script, or the clock will reset to the specified time again.

这篇关于如何设置primefaces时钟小部件的开始时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆