0

Component refresh and Threads (Components can be accessed only in event listeners)

asked 2011-03-01 11:38:01 +0800

lcarlesso gravatar image lcarlesso
21 1

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"..

delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest
link publish delete flag offensive edit

answered 2011-03-02 11:40:23 +0800

lcarlesso gravatar image lcarlesso
21 1
Maik, thanks for the links, But dont works for me, I think I have something wrong at some place. My tests details: zk.xml ...
<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");
            }
        }
    }
}
When I try do enable the push I got this error: Exception in thread "Thread-24" java.lang.IllegalStateException: Server Push cannot be started without execution at org.zkoss.zk.ui.impl.DesktopImpl.enableServerPush0(DesktopImpl.java:1277) at org.zkoss.zk.ui.impl.DesktopImpl.enableServerPush(DesktopImpl.java:1265) Anyone see whats happening?
link publish delete flag offensive edit

answered 2011-03-02 12:12:52 +0800

mjablonski gravatar image mjablonski
1284 3 5
http://www.jease.org/

updated 2011-03-02 12:13:09 +0800

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

link publish delete flag offensive edit

answered 2011-03-02 13:13:37 +0800

lcarlesso gravatar image lcarlesso
21 1

Hey Maik.. =D

A lot of thanks.. It works perfect =D.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2011-03-01 11:38:01 +0800

Seen: 1,196 times

Last updated: Mar 02 '11

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More