vaadin / flow-components

Java counterpart of Vaadin Web Components
101 stars 66 forks source link

setEnabled for the component editor fails with NPE #1281

Open anasmi opened 5 years ago

anasmi commented 5 years ago

Grid-pro:1.0.0 Affected line: ((HasEnabled)grid.getColumnByKey("city") .getEditorComponent()).setEnabled(false); Code to reproduce:

public class ProGridView extends VerticalLayout {
        GridPro<Person> grid;
        public ProGridView(){
                add(createGridPro());
                add(new Button("Change editor", e->{
//NPE here
       ((HasEnabled)grid.getColumnByKey("city")
            .getEditorComponent()).setEnabled(false);
                }));
        }
        private GridPro createGridPro(){
                grid = new GridPro<>();
                grid.addColumn(Person::getFirstName).setEditorComponent(new TextField()).setHeader("First Name").setKey("firstName");
                grid.addEditColumn(Person::getLastName).text((oldValue,newValue)->{}).setHeader("Last name").setKey("lastName");
                grid.addEditColumn(Person::getCity).select((oldValue,newValue)->{},
                        PersonRepository.getCities()).setHeader("Cities").setKey("city");
                grid.addEditColumn(Person::getAge);
                grid.setItems(new PersonRepository().getPersons());
                return grid;
        }
}

Might be related to this: https://github.com/vaadin/vaadin-grid-flow/issues/604

taefi commented 1 year ago

The following workaround might help: https://cookbook.vaadin.com/grid-pro-conditional-edit

I created a feature request that can address this as well here: https://github.com/vaadin/flow-components/issues/4524