Search code examples
javagwtgwt2

GWT listbox not getting populated


I m using gwt 2.6.0. I have a listbox on my page which is popluated using the following code

    public void setOHIInfo(ArrayList<OHIInfoTo> result) {
    ohiListBox.setEnabled(true); // ohiListBox is instance of com.google.gwt.user.client.ui.ListBox
    for (OHIInfoTo ohiinfo : result) {
        ohiListBox.addItem(ohiinfo.getOhiName(), ohiinfo.getOhiName());
        GWT.log(ohiinfo.getOhiName()); // 5 data items are printed; no spaces
    }
    GWT.log("OHI Count - " + ohiListBox.getItemCount()); // Prints OHI Count - 5
}

The 2 GWT.log lines are getting printed when the page loads, but the listbox is blank. I have searched in the project, there is no other place which is overwriting the listbox. I have also inspected the listbox element in chrome, it is actually not having any

Any other way to find what is going wrong here?


Solution

  • Finally Solved this !!! The call to setOHIInfo was async. So, this method was getting executed almost in parallel to the constructor and finishing before the listbox was rednered. Somehow, it did not throw null pointer exception. That is still a mystery.

    To fix - I ensured that the listbox is rendered first and then the values are set.