简体   繁体   English

JSF数字时钟

[英]JSF digital clock

What would be the best way to implement a digital clock in JSF 2.0?在 JSF 2.0 中实现数字时钟的最佳方法是什么? Is there a lib or component available or should I implement it myself?是否有可用的库或组件,或者我应该自己实现它? In the latter case, what would be the best way to implement it?在后一种情况下,实现它的最佳方法是什么? The clock only should - obviously- be refreshed automatically on the page when a minute goes by.时钟只应该 - 显然 - 在一分钟过去后在页面上自动刷新。 I wish not to use JavaScript.我不想使用 JavaScript。

Thanks in advance.提前致谢。

What would be the best way to implement a digital clock in JSF 2.0?在 JSF 2.0 中实现数字时钟的最佳方法是什么? Is there a lib or component available or should I implement it myself?是否有可用的库或组件,或者我应该自己实现它?

No JSF component comes to mind.没有想到 JSF 组件。 You'd need to implement it yourself.你需要自己实现它。


In the latter case, what would be the best way to implement it?在后一种情况下,实现它的最佳方法是什么? The clock only should - obviously- be refreshed automatically on the page when a minute goes by.时钟只应该 - 显然 - 在一分钟过去后在页面上自动刷新。 I wish not to use JavaScript.我不想使用 JavaScript。

Use JavaScript.使用 JavaScript。 There is really no better/easier way.真的没有更好/更简单的方法。 Plus, there are lot of ready-to-use examples available on the internet.此外,互联网上有很多现成的示例可用。


As far as I know I'll need <body onload="showTime()"> to activate the code for the clock.据我所知,我需要<body onload="showTime()">来激活时钟代码。 But then I'd be activating the JavaScript on pages where it shouldn't be activated.但随后我将在不应激活的页面上激活 JavaScript。 Or is there a way without using the onload trigger event?或者有没有办法不使用 onload 触发事件?

Just put a放一个

<script>window.onload = functionName;</script>

somewhere in the document.文档中的某处。 It'll work equally good.它会同样好用。 You can also just do你也可以这样做

<script>functionName();</script>

as long as that appears after the HTML DOM element representing the clock.只要它出现代表时钟的 HTML DOM 元素之后。

Without javascript, the HTML header Meta tags没有 javascript、HTML header 元标记

<meta http-equiv="refresh" content=".."  />

is the only method that comes to my mind,是我想到的唯一方法,

Using that you can reload the page every second, but it is an ugly solution.使用它,您可以每秒重新加载页面,但这是一个丑陋的解决方案。

Otherwise:否则:

  • Javascript (everybodys favorite) Javascript(大家都喜欢)
  • Flash (no Javascript) Flash(无 Javascript)
  • Java Applets (yes they still exist and hey no javascript). Java 小程序(是的,它们仍然存在,嘿,没有 javascript)。

I'd strongly suggest using Javascript, since a no Javascript policy and JSF makes no sense.我强烈建议使用 Javascript,因为没有 Javascript 策略和 JSF 没有任何意义。 This would even deny simple Components like HTMLCommandlinks, since those cannot be used without Javascript, just take a look at all the Javascript your JSF implementation actually creates.这甚至会拒绝 HTMLCommandlinks 之类的简单组件,因为没有 Javascript 就无法使用这些组件,只需查看您的 Z798476CFD70310827337C1DDFDCC4D664Z 实现实际创建的所有 Javascript 即可。

you can use primefaces, it has done many things for you.您可以使用 primefaces,它为您做了很多事情。 see: http://www.primefaces.org/showcase/ui/clock.jsf见: http://www.primefaces.org/showcase/ui/clock.jsf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM