So for example let's I have:
public class MainView extends AppLayout {
public MainView() {
User user = VaadinSession.getAttribute("user");
if(user.isCheckSomething())
Span span = new Span("Hello " + user.getFirstname());
}
}
This will fail with a NPE if the user is not already logged in as getting the User from the session will be null. Now I could add a null check before the if(user.isCheckSomething()) but ideally I would prefer not to have the AppLayout rendered at all if the user is not logged in. That is I'd rather fail in the view through BeforeEnterObserver in the public void beforeEnter(BeforeEnterEvent event) method however the AppLayout is called and created before the beforeEnter(...) method is called.
In other words how can I force the instantiation of AppLayout to be skipped entirely if the user isn't logged in through the view so that the AppLayout is never constructed.