![]()
Enhancing the TimeZoneBean
Now that we've integrated ICEfaces, the work to make the clocks tick is done in the bean. To make the clock tick every second, we are going to create our own thread and have it send updates at a set interval. We also need to add a bit of ICEfaces-specific code to force a JSF render pass after the clock data has been updated. For timezone3, the following changes are made to the TimeZoneBean.java file.
import com.icesoft.faces.webapp.xmlhttp.PersistentFacesState;public class TimeZoneBean implements Runnable {/** * Time thread sleeps between polls. */ private int pollInterval = 500;/** * Constructor, initializes time zones and starts thread which * updates the time. */ public TimeZoneBean() { init(); Thread ticker = new Thread(this); ticker.start(); }5. Then we add a run method to implement the Runnable interface. When the thread runs, it gets a reference to the PersistentFacesState from the HttpSession. This state can be used to initiate a render pass, which triggers the dynamic update to the client. The bean sleeps for the specified polling interval in between calls to render.
public void run() { try { while (0 != pollInterval) { PersistentFacesState state = PersistentFacesState.getInstance(); Thread.sleep(pollInterval); if (null != state) { state.render(); } else { System.out.println("null PersistentFacesState"); break; } } } catch (Exception e) { System.out.println(e); } }
|
Copyright 2005. ICEsoft Technologies, Inc. http://www.icesoft.com |