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?
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);
}
}
You could look into GWT's IncrementalCommand which can help with long running calculations.
精彩评论