Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Removing binding does not remove all references #3405

Closed
brp-oskar opened this issue Jan 26, 2018 · 2 comments
Closed

Removing binding does not remove all references #3405

brp-oskar opened this issue Jan 26, 2018 · 2 comments

Comments

@brp-oskar
Copy link

brp-oskar commented Jan 26, 2018

When removing a binding (for a field) from a binder I want the framework to remove references to that binding so that I can add a new binding for the same field.

When calling Binder::removeBinding() the binding is not removed from the Set<Binding<BEAN, ?>> changedBindings. This results in a NPE when calling Binder::validate() because it will call an unbinded binding. (update: I cannot reproduce this error anymore)

@brp-oskar brp-oskar changed the title Removing binding does not clean changedBindings Removing binding does not remove all references Jan 29, 2018
@brp-oskar
Copy link
Author

I'm sorry for providing such incomplete information but I can't get it working with replacing a binding for a field.

I have checked out the combo-box-flow project and added a "card" where I can reproduce another error where the binding is not correctly removed. I think it is the client side that calls the server with an old binding reference. An important thing is that I'm calling binder.setBean(song).

Here is my code snippet with instructions how to get the error.

    private void createStringComboBoxWithBinder() {
        Div message = createMessageDiv("string-selection-message-with-binder");

        // begin-source-example
        // source-example-heading: String selection with binder

        // 1. Select 'Google Chrome'
        // 2. Click 'Validate'
        // 3. Clear selection
        // 4. Click 'Not required'
        // 5. Results in
        //      java.lang.NullPointerException: This Binding is no longer attached to a Binder

        Song song = new Song();
        Binder<Song> binder = new Binder<>();

        ComboBox<String> comboBox = new ComboBox<>("Browsers");
        comboBox.setItems("Google Chrome", "Mozilla Firefox", "Opera",
                "Apple Safari", "Microsoft Edge");

        comboBox.addValueChangeListener(event -> {
            if (event.getSource().isEmpty()) {
                message.setText("No browser selected");
            } else {
                message.setText("Selected browser: " + event.getValue());
            }
        });

        NativeButton requiredButton = new NativeButton("Set required", e -> {
            binder.removeBinding(comboBox);
            Binder.Binding<Song, String> binding = binder.forField(comboBox)
                    .asRequired()
                    .bind(Song::getName, Song::setName);
            binding.read(song);
        });

        NativeButton notRequiredButton = new NativeButton("Not required", e -> {
            binder.removeBinding(comboBox);
            Binder.Binding<Song, String> binding = binder.forField(comboBox)
                    .bind(Song::getName, Song::setName);
            binding.read(song);
        });

        NativeButton validateButton = new NativeButton("Validate", e -> binder.validate());

        binder.forField(comboBox)
                .asRequired()
                .bind(Song::getName, Song::setName);

        binder.setBean(song);

        // end-source-example

        comboBox.getStyle().set(ElementConstants.STYLE_WIDTH, WIDTH_STRING);
        comboBox.setId("string-selection-box-with-binder");
        addCard("String selection with binder", requiredButton, notRequiredButton, validateButton, comboBox, message);
    }

@pleku pleku added this to the 1.0 Maintenance milestone Mar 25, 2018
@pleku pleku removed this from the 1.0 Maintenance milestone Apr 24, 2020
@denis-anisimov
Copy link
Contributor

This is a duplicate of #5384 which is already fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants