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
.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With