Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vaadin UI.getcurrent returns null in request handler

Why does the UI.getCurrent method in vaadin return null, but the getUI() actualy returns the UI in a same case. For example:

    @Override
    public boolean handleRequest(VaadinSession session,VaadinRequest request, VaadinResponse        response)
                throws IOException {

            UI.getCurrent(); //returns null
            getUI(); //works

            return false;
        }

I'm trying to make a login page with custom layout (to keep the autofill) since vaadin suppressed the LoginForm.

like image 218
John342 Avatar asked Oct 20 '22 20:10

John342


1 Answers

The difference between the two methods or ways to get the UI are stated as follows in the Book of Vaadin.

https://vaadin.com/book/-/page/advanced.global.html

Vaadin offers two ways to access the UI object: with getUI() method from any component and the global UI.getCurrent() method.

The getUI() works as follows:

data = ((MyUI)component.getUI()).getUserData();

This does not, however work in many cases, because it requires that the components are attached to the UI. That is not the case most of the time when the UI is still being built, such as in constructors.

The global access methods for the currently served servlet, session, and UI allow an easy way to access the data:

data = ((MyUI) UI.getCurrent()).getUserData();
like image 125
crabe Avatar answered Oct 22 '22 21:10

crabe