开发者

How to create a timer counter in JSF

开发者 https://www.devze.com 2023-01-25 10:36 出处:网络
I want to create an online test system, so i nee开发者_开发知识库d a timer. When user start the test the timer will start counting down. But when user go to next question refresh the page the timer wi

I want to create an online test system, so i nee开发者_开发知识库d a timer. When user start the test the timer will start counting down. But when user go to next question refresh the page the timer will still running. How can I do that any suggestion?


You can use PrimeFaces Poll option.

The counter will always be saved on the server.


You can also use PrimeFaces Extensions, they have timer in their API.

Example: you put start of the test into @SessionScoped bean, then calculate seconds remaining which will be used as an input to <pe:timer> element:

@SessionScoped
public class UserData {
     private Date testStart; 

     /* getters and setters for testStart */

     public int secondsRemaining() {
        //calculate seconds remaining until end of the test from this.testStart
        return secondsRemaining;
     }
}

and then your test.xhtml would contain element

Time remaining: <pe:timer format="HH:mm:ss"
                    timeout="#{userData.secondsRemaining()}"/> 
0

精彩评论

暂无评论...
验证码 换一张
取 消