Vaadin14: Handle a critical error (null-object in applyValueProvider for Grid)

44 views Asked by At

I have prepared a simple example in which a critical error occurs. This is due to the null-object in the Grid field (when the applyValueProvider method is executed) Critical Message

public class ViewCriticalError extends VerticalLayout {

    public ViewCriticalError() {
        Grid<Person> personGrid = new Grid<>(Person.class);

        String nullErrorValue = null;

        personGrid.setColumns("firstName");
        personGrid.addColumn(person -> nullErrorValue.toString());

        personGrid.setItems(Arrays.asList(new Person("Alex")));

        add(personGrid);
    }

    class Person{
        private String firstName;

        public Person(String firstName) {
            this.firstName = firstName;
        }

        public String getFirstName() {
            return firstName;
        }
    }
}

The problem is that after this critical message, the page is completely reloaded and the user's entered data is destroyed.

Is there any way I can catch this error and prevent the page from refreshing?

I used VaadinServiceInitListener(addSessionInitListener -> vaadinSession.setErrorHandler) but it gets a wrapped error and fails to catch the critical message. Still a critical message appears and the page needs to be reloaded

Vaadin / Flow version: 14.10.3

I found two similar posts (but without a solution to the problem): https://github.com/vaadin/flow/issues/16806?ysclid=lmbtyhgcm6836979057 https://github.com/vaadin/framework/issues/1768?ysclid=lmappnflvx903746789

0

There are 0 answers