如何在 JSF 中创建计时器

发布于 2024-10-02 10:16:08 字数 92 浏览 0 评论 0原文

我想创建一个在线测试系统,所以我需要一个计时器。当用户开始测试时,计时器将开始倒计时。但是,当用户转到下一个问题刷新页面时,计时器仍将运行。我怎样才能做到这一点任何建议?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

音栖息无 2024-10-09 10:16:08

您可以使用 PrimeFaces 投票 选项。

计数器将始终保存在服务器上。

You can use PrimeFaces Poll option.

The counter will always be saved on the server.

时光是把杀猪刀 2024-10-09 10:16:08

您还可以使用 PrimeFaces Extensions,它们的 API 中有计时器

示例:您将测试开始放入 @SessionScoped bean,然后计算剩余秒数,该秒数将用作 元素的输入:

@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;
     }
}

然后您的test.xhtml 将包含元素

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

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()}"/> 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文