pe:timer with milliseconds [Solved]

Community Driven Extensions Project
Post Reply
marcoszamparo
Posts: 4
Joined: 02 Sep 2014, 20:11

29 Jan 2019, 18:39

Is there a way to run pe:timer with milliseconds than seconds?
I need to run a timer each 100 milliseconds.
Thanks
Last edited by marcoszamparo on 30 Jan 2019, 19:47, edited 1 time in total.
Primefaces 6.1

User avatar
Melloware
Posts: 910
Joined: 22 Apr 2013, 15:48

30 Jan 2019, 14:41

Yes. Add the below JavaScript to your page to override the "start" method of the widget to set the interval to 100 instead of 1000.

Code: Select all

PrimeFaces.widget.ExtTimer.prototype.start = function() {
    var that = this;
    var end;
    this.prevTime = this.currentTimeInSecs();

    if(!this.interval){
        this.interval = setInterval(function(){
            that.doStep();

            end = that.forward ? that.currentTimeout >= that.originalTimeout : that.currentTimeout <= 0;

            if(end){
                if(that.cfg.listener){
                    that.cfg.listener();
                }
                if(that.cfg.ontimercomplete){
                    that.cfg.ontimercomplete();
                }
                if(that.cfg.singleRun){
                    clearInterval(that.interval);
                    this.interval = null;
                }else{
                    that.currentTimeout = that.forward ? 0 : that.originalTimeout;
                    that.print();
                }
            }
        }, 100);
    }
}
PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 6.2.10 / PF Extensions 6.2.9

marcoszamparo
Posts: 4
Joined: 02 Sep 2014, 20:11

30 Jan 2019, 19:46

Thanks! It worked! :D
Primefaces 6.1

User avatar
Melloware
Posts: 910
Joined: 22 Apr 2013, 15:48

30 Jan 2019, 19:48

Nice!!!
PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 6.2.10 / PF Extensions 6.2.9

User avatar
Melloware
Posts: 910
Joined: 22 Apr 2013, 15:48

31 Jan 2019, 14:29

Just an FYI I added an "interval" attribute to pe:timer for 7.0 so you can configure this as an attribute.

See ticket: https://github.com/primefaces-extension ... issues/645
PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 6.2.10 / PF Extensions 6.2.9

Post Reply

Return to “Extensions”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 2 guests