Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Error "this.selectedItem is undefined" when add new items to ChosenListBox and update it #271

Closed
conargon opened this issue Oct 2, 2015 · 2 comments
Assignees
Labels

Comments

@conargon
Copy link

conargon commented Oct 2, 2015

I'm testing the new ChosenListBox release 3.0. When I add new items dinamically or when I set some items as selected, I get the exception this.selectedItem is undefined.

Test code:

    public void onModuleLoad() {
        final Button testButton = new Button("Test");

        final ChosenListBox chosen = new ChosenListBox(true);
        chosen.setWidth("100%");
        chosen.addItem("uno");
        chosen.addItem("dos");
        chosen.addItem("tres");

        RootPanel.get("chosenContainer").add(chosen);
        RootPanel.get("sendButtonContainer").add(testButton);

        testButton.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                chosen.addItem("cuatro");
                chosen.addItem("cinco");
                chosen.addItem("seis");
                chosen.update();
//              chosen.setItemSelected(0, true);
            }
        });
    }

I debugged the Java source and I saw the GQuery selectedItem private attribute of ChosenImpl class is never initialized when the ChosenListBox is multivalue.This is, the method initSearchElement, where the attribute selectedItem is initialized, is never called in this case.

The problem is that the method update() of ChosenListBox class fires events, and the handler vents references to selectedItem. See method update() of DesktopMultipleChosenImpl class and finally method resultsResetCleanup of ChosenImpl class. This last method references to selectedItem and crash.

I think the method initSearchElement of DesktopMultipleChosenImpl class should initialize selectedItem attribute.

@christiangoudreau
Copy link
Member

Thanks for sharing this with us! We'll look into this.

@olafleur olafleur added the bug label Oct 5, 2015
meriouma added a commit that referenced this issue Oct 15, 2015
meriouma added a commit that referenced this issue Oct 16, 2015
Fix for #271 : "this.selectedItem is undefined" when adding new items to ChosenListBox and calling update()
@meriouma
Copy link
Member

Please reopen the issue if it still happens with new 3.1-SNAPSHOT. Thanks!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants