Artur Signell:
You are reading the attribute when doing new Home(session). That is way before the clicklistener has been invoked and set the value
like this?
`WrappedSession session = vaadinRequest.getWrappedSession();
Home h = new Home(session);
TextField name = new TextField("User: ");
Button button = new Button("Click");
button.addClickListener(e -> {
vaadinRequest.getWrappedSession().setAttribute("user", name.getValue());
nav.navigateTo(home);
});`
i get the same result when I run the application
The problem is that you read the value when the UI is first loaded, with w.getAttribute("user"), but you only set the value inside the click listener, which runs when the user has clicked the button. For instance, something this should work:
// Move the code from the constructor to a method
class Home extends VerticalLayout implements View {
public Home() {}
public void addLabel(String user) {
addComponent(new Label("Home " + user));
}
}
Then in MyUI
// Call the method created in Home inside the click listener
button.addClickListener(e -> {
h.addLabel(name.getValue());
nav.navigateTo(home);
});