-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Anyone knows how can I solve this?
See the code:
final EventListener dvn = new EventListener() { public void onEvent(Event event) throws Exception { ar.setValue( ar.getValue()+"..." ); } }; try { Executions.getCurrent().getDesktop().enableServerPush(true); Executions.activate(Executions.getCurrent().getDesktop()); new Thread(new Runnable() { public void run() { while (true) { try { Thread.sleep(1000); dvn.onEvent(new Event("evnt")); } catch( Exception e ) { } } } }).start(); } catch (Exception ex) { Logger.getLogger(LauncherApplicationPane.class.getName()).log(Level.SEVERE, null, ex); }
Im getting this error:
"Components can be accessed only in event listeners"..
<preference> <name>PollingServerPush.delay.min</name> <value>3000</value> </preference> <preference> <name>PollingServerPush.delay.max</name> <value>10000</value> </preference> <preference> <name>PollingServerPush.delay.factor</name> <value>5</value> </preference> <device-config> <device-type>ajax</device-type> <server-push-class>org.zkoss.zk.ui.impl.PollingServerPush</server-push-class> </device-config>
public class Pane extends Div { final Label ar = new Label("asdfasdf"); Desktop _desktop; public LauncherApplicationPane() { appendChild( ar ); _desktop = Executions.getCurrent().getDesktop(); new WorkingThread().start(); } class WorkingThread extends Thread { public void run() { try { while (true) { _desktop.enableServerPush(true); Executions.activate(_desktop); try { ar.setValue(ar.getValue()+"..."); } finally { Executions.deactivate(_desktop); } Threads.sleep(1000); } } catch (DesktopUnavailableException ex) { System.out.println("The server push thread interrupted"); } catch (InterruptedException e) { System.out.println("The server push thread interrupted"); } } } }
You'll have to enable serverPush before you can use it in a thread Please change LauncherApplicationPane() like this:
_desktop = Executions.getCurrent().getDesktop(); _desktop.enableServerPush(true);
Cheers, Maik
Asked: 2011-03-01 11:38:01 +0800
Seen: 1,198 times
Last updated: Mar 02 '11