1

例如,我有一个 html 跨度,当应用程序进行一些测试时应该更新它(比如发布,然后等待一段时间等待响应并表示结果)。所以我想在这个跨度上展示这个动作的当前进展。

我尝试在扩展 WebPage 的 myPage.java 中创建线程。它的定义是:

class TestThread extends Thread{

    private Label current_message_lbl;
    private Component component;

    public void run() {
        try {
            this.sleep(1000);
            current_message_lbl.setDefaultModelObject(new StringResourceModel("test-SENDING-COMMANDS",component, null));
                    /* HTTP POST and other test code*/

        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }

    public void setCurrentMesssageLabel(Label current_message_lbl){
        this.current_message_lbl = current_message_lbl;
    }
    public void setComponent(Component component){
        this.component = component;
    }
}

我从以下开始:

TestThread thread = new TestThread();
thread.setCurrentMesssageLabel(current_message_lbl);
thread.setComponent(component);
thread.start();

在我收到此错误消息后

当前线程 Thread-103 没有附加应用程序

我也尝试过定义线程,如:

class TestThread extends WicketApplication implements Runnable{
4

1 回答 1

4

您可以将AjaxSelfUpdatingTimeBehavior添加到您的组件中。比此行为每隔几秒更新一次组件。但是你必须在你的线程中改变组件的模型。

Also if you try to lazy load a component you can check AjaxLazyLoadPanel. There are some examples in here and here.

于 2012-06-04T10:50:36.360 回答