Bart1990
Bart1990

Reputation: 255

JSF digital clock

What would be the best way to implement a digital clock in 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.

Thanks in advance.

Upvotes: 0

Views: 2134

Answers (3)

chero
chero

Reputation: 43

you can use primefaces, it has done many things for you. see:http://www.primefaces.org/showcase/ui/clock.jsf

Upvotes: 0

Chrstian Beutenmueller
Chrstian Beutenmueller

Reputation: 807

Without javascript, the HTML header Meta tags

<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)
  • Flash (no Javascript)
  • Java Applets (yes they still exist and hey no javascript).

I'd strongly suggest using Javascript, since a no Javascript policy and JSF makes no sense. 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.

Upvotes: 0

BalusC
BalusC

Reputation: 1108722

What would be the best way to implement a digital clock in JSF 2.0? Is there a lib or component available or should I implement it myself?

No JSF component comes to mind. 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.

Use 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. But then I'd be activating the JavaScript on pages where it shouldn't be activated. Or is there a way without using the onload trigger event?

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.

Upvotes: 1

Related Questions