user236501
user236501

Reputation: 8648

How to create a timer counter in JSF

I want to create an online test system, so i need 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?

Upvotes: 0

Views: 12968

Answers (2)

Dejell
Dejell

Reputation: 14337

You can use PrimeFaces Poll option.

The counter will always be saved on the server.

Upvotes: 2

Mišo Stankay
Mišo Stankay

Reputation: 339

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()}"/> 

Upvotes: 1

Related Questions