Get login parameters (of login) in the home class

When I show the wrappedsession.getAttribute("user") in the main class it shows null in the navigator

This is the main ui MainUI.class extends from UI

protected void init(VaadinRequest vaadinRequest) {
		String home = "home";
    	WrappedSession session = vaadinRequest.getWrappedSession();
    	Navigator nav = new Navigator(this,this);
        VerticalLayout layout = new VerticalLayout();
        TextField name = new TextField();
        name.setCaption("User:");
        Button button = new Button("Click");
        button.addClickListener(e -> {
        	vaadinRequest.getWrappedSession().setAttribute("user", name.getValue());
        	nav.navigateTo(home);
        });
        Home h = new Home(session);
        nav.addView(home, h);
        layout.addComponents(name, button);
        setContent(layout);
    }

this is the home class extends from verticallayout extends view

public Home(WrappedSession w) {
		addComponent(new Label("Home " + w.getAttribute("user") ));
	}

below there are the screenshots

17164415.png
17164418.png
17164421.png
17164424.png

You are reading the attribute when doing new Home(session). That is way before the clicklistener has been invoked and set the value

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);
});