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()}"/>
精彩评论