由于 listBox 的 onChange 事件处理程序中的繁重处理,GWT UI 未更新

发布于 2024-11-28 21:03:55 字数 1189 浏览 2 评论 0原文

我有一个列表框,在其 onChange() 上,我正在更新另一个列表框。 所以代码就像这样

ListBox l1 = new ListBox();
...some items added to l1..

ListBox l2 = new ListBox();
l2.setEnabled(false);

l1.addChangeHandler(new ChangeHandler() {               
    @Override
    public void onChange(ChangeEvent event) {
         //Show info msg
         //Update label text on top of the page with "Loading.."

        //..Do some processing here..

        L2.setEnabled(true);
        L2.getElement().setInnerHTML(html);
    }

,除了一个小故障之外,一切正常。 UI 被卡住,并且 l1、l2 和标签在处理完成之前都不会反映更改。 l2 当然会在稍后的时间点反映,但 l1 和信息也不会显示。

我尝试使用 ScheduledDeferred 作为 --

l1.addChangeHandler(new ChangeHandler() {               
    @Override
    public void onChange(ChangeEvent event) {
         //Show info msg
         //Update label text on top of the page with "Loading.."

         Scheduler.get().scheduleDeferred(new ScheduledCommand() {
             @Overide
             public void execute() {
                //..Do some processing here..
            }
        }

         L2.setEnabled(true);
         L2.getElement().setInnerHTML(html);
    }
}

但上面仍然没有帮助,它仍然照常工作。有什么建议吗?

I have a list Box, on whose onChange(), I am updating another listBox.
So the code is something like

ListBox l1 = new ListBox();
...some items added to l1..

ListBox l2 = new ListBox();
l2.setEnabled(false);

l1.addChangeHandler(new ChangeHandler() {               
    @Override
    public void onChange(ChangeEvent event) {
         //Show info msg
         //Update label text on top of the page with "Loading.."

        //..Do some processing here..

        L2.setEnabled(true);
        L2.getElement().setInnerHTML(html);
    }

This is working all fine, except for one glitch. The UI is stuck and both l1, l2 and label don't reflect the change until the processing is done. l2 would ofcourse reflect at later point of time, but l1 and info aren't showing up either.

I tried using scheduledDeferred as --

l1.addChangeHandler(new ChangeHandler() {               
    @Override
    public void onChange(ChangeEvent event) {
         //Show info msg
         //Update label text on top of the page with "Loading.."

         Scheduler.get().scheduleDeferred(new ScheduledCommand() {
             @Overide
             public void execute() {
                //..Do some processing here..
            }
        }

         L2.setEnabled(true);
         L2.getElement().setInnerHTML(html);
    }
}

But above is still not helping, it's still working as usual. Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

请止步禁区 2024-12-05 21:03:56

您可以查看 GWT 的 IncrementalCommand可以帮助进行长时间运行的计算。

You could look into GWT's IncrementalCommand which can help with long running calculations.

花心好男孩 2024-12-05 21:03:55

计划命令执行的操作与前面的代码片段完全相同 - 它执行一些处理,然后更新 UI。您需要做的是首先更新 UI,然后执行处理(希望处理不会锁定浏览器)。

试试这个:

l1.addChangeHandler(new ChangeHandler() {               
    @Override
    public void onChange(ChangeEvent event) {
         //Show info msg
         //Update label text on top of the page with "Loading.."

         Scheduler.get().scheduleDeferred(new ScheduledCommand() {
             @Overide
             public void execute() {
                //..Do some processing here....
               performSomethingReallyExpensive();
            }
        }
        L2.setEnabled(true);
        //hopefully, this 'html' variable doesn't depend on performSomethingReallyExpensive()...
        L2.getElement().setInnerHTML(html); 
    }
}

The scheduled command does exactly the same thing as the previous snippet - it performs some processing, then updates the UI. what you need to do is first update the UI, then perform the processing (hopefully the processing doesn't lock up the browser) .

try this:

l1.addChangeHandler(new ChangeHandler() {               
    @Override
    public void onChange(ChangeEvent event) {
         //Show info msg
         //Update label text on top of the page with "Loading.."

         Scheduler.get().scheduleDeferred(new ScheduledCommand() {
             @Overide
             public void execute() {
                //..Do some processing here....
               performSomethingReallyExpensive();
            }
        }
        L2.setEnabled(true);
        //hopefully, this 'html' variable doesn't depend on performSomethingReallyExpensive()...
        L2.getElement().setInnerHTML(html); 
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文