Initializing form

I initialize form for registrartion

private User user = new User(login, password); private User user1 = new User(login, password); private RegistrationView registrationView = new RegistrationView(user); When I setVisible(true) for this form, it get information about user, and setValue in components according to user’s information. BUT if I will change user like

user = user1; then form doesn’t get this information about user1, but contains information about user.
I also tried make it

registrationView = new RegistrationView(user1); but after it I doesn’t arrear.

How can I solve this problem, if I need to get information about user1, after information about user?

Hi,

instead of passing the User as a parameter to the constructor of RegistrationView, you should add a public method like updateUser(User user) and update the contents of the view there. Changing the user object pointer or the view pointer won’t do anything automatically.

Let me know if you have more questions,
Olli

Could you give me example your’s view of method updateUser(User) ?

Hi,

maybe something like this:

public class RegistrationView extends FormLayout {

  private TextField usernameField = new TextField("username: ");
  private PasswordField passwordField = new PasswordField("password: ");

  public RegistrationView() {
      addComponent(usernameField);
      addComponent(passwordField);
  }

  public updateUser(User user) {
    usernameField.setValue(user.getUsername());
    passwordField.setValue(user.getPassword());
  }  
  
}

Hope this helps,
-Olli

Yes, Thank you a lot)

You’re welcome!

-Olli