Data disappear when ValueChangeListenet fired.

I’ve a very simple form with 2 text fields username and password and a combobox for the language.
The username field has setImmediate = true and a ValueChangeListener which set the default language for the choosen user in the combobox.
Using the form if I type username and password fastly I get the following behaviour : the listener fires and set the language correctly but the already typed password disappears (note that the typed value is retained but not visible).
If I type slowly everything works fine.
How can I avoid such bad behaviour ?
Tks
Tullio

Sounds weird, do you have a simple testcase you could provide?

As a side note, if I understood correctly, when the user types his username, the application will query a database and check the user’s preferred language based on the username, before the user types his password, right? This could be considered as a security issue, because good security practices dictate that you shouldn’t expose any information about the login information - for example, you shouldn’t tell the user that “Username not found” or “Password incorrect”, because that would expose information about valid usernames. If I understood your application’s behaviour correctly, you are also exposing information about your usernames through changing the language when a valid username is entered. See
OWASP
for more details.

Here the code

public class LoginPaxlet extends AbstractPaxlet {

private static final long serialVersionUID = 1L;

@Autowired
private AuthContext authContext;
@Autowired
private LanguageService lingueService;
@Autowired
private UtenteTmplService utenteService;
@Autowired
private LanguageContext languageContext;
private final DateFormat yearFormat = new SimpleDateFormat("yyyy");
private VerticalLayout loginBox = new VerticalLayout();
private StringField tfUsername;
private PasswordField tfPassword;
private ComboBox cbLingue;
private TranslatableButton btnLogin;
private Embedded logo;
private Map<String, Language> lingueMap = new HashMap<String,Language>();

@Override
protected void initPaxlet() throws PaxletConfigurationException {
}

@Override
protected void initOnAttach() throws PaxletConfigurationException {
    addStyleName("tmpl-login-paxlet");
    Filler lblSepTop = new Filler();
    addComponent(lblSepTop);
    setExpandRatio(lblSepTop, 0.5f);
    buildLoginBox();
    addComponent(loginBox);
    setComponentAlignment(loginBox, Alignment.MIDDLE_CENTER);
    Link lnkFoot = new Link("Copyright " + yearFormat.format(new Date()) + " Axioma", new ExternalResource("http://www.axioma.it"));
    lnkFoot.setTargetName("_blank");
    lnkFoot.addStyleName("tmpl-login-footer");
    lnkFoot.setSizeUndefined();
    addComponent(lnkFoot);
    setComponentAlignment(lnkFoot, Alignment.BOTTOM_CENTER);
    Filler lblSepBottom = new Filler();
    addComponent(lblSepBottom);
    setExpandRatio(lblSepBottom, 0.5f);
    tfUsername.focus();
}

@SuppressWarnings("unchecked")
private void buildLoginBox()  {
    loginBox.setMargin(true);
    loginBox.setSpacing(true);
    loginBox.setWidth("30%");
    loginBox.addStyleName("tmpl-login-box");
    loginBox.removeAllComponents();
    logo = new Embedded(null, UiUtils.getImage("images/login.png"));
    logo.setSizeUndefined();
    tfUsername = new StringField("Username","Login.field.username");        
    tfUsername.setMaxLength(100);
    tfUsername.addStyleName("tmpl-login-username");
    tfUsername.setRequired(true);
    tfUsername.setPropertyName("username");        
    tfUsername.setErrorNotifier(getApplicationServices().getDefaultErrorNotifier());
    tfUsername.addValueChangeListener(new ValueChangeListener(){

        private static final long serialVersionUID = 1L;

        @Override
        public void valueChange(ValueChangeEvent xpEvent) {
            String userName = (String) xpEvent.getProperty().getValue();
            cambioUtente(userName);
        }
        
    });
    tfPassword = new PasswordField("Password","Login.field.password");
    tfPassword.setRequired(true);
    tfPassword.addStyleName("tmpl-login-password");
    tfUsername.setMaxLength(100);
    tfPassword.setPropertyName("password");
    tfPassword.setErrorNotifier(getApplicationServices().getDefaultErrorNotifier());
    cbLingue = new ComboBox("Languages");
    cbLingue.addStyleName("tmpl-login-lingue");
    cbLingue.setRequired(true);
    try {
        List<Language>lingue = (List<Language>) lingueService.getLanguages();
        for(Language lingua : lingue) {
            String code = lingua.getLanguageCode();
            cbLingue.addItem(code);
            cbLingue.setItemCaption(code,lingua.getDescription());
            lingueMap.put(code, lingua);
        }
    } catch (LanguageException ex) {}
    cbLingue.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void valueChange(ValueChangeEvent xpEvent) {
            String lingua = (String) xpEvent.getProperty().getValue();
            setLingua(lingua);
        }
        
    });
    btnLogin = new TranslatableButton("Login","Login.button.login");
    btnLogin.setIcon(UiUtils.getIcon("icons/template/accept.png"));
    btnLogin.addStyleName("tmpl-login-button");
    btnLogin.setClickShortcut(KeyCode.ENTER);
    btnLogin.setWidth(10, Unit.EM);
    btnLogin.addClickListener(new Button.ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent xpEvent) {
            doLogin();
        }

    });
    loginBox.addComponent(logo);
    loginBox.addComponent(tfUsername);
    loginBox.addComponent(tfPassword);
    loginBox.addComponent(cbLingue);
    loginBox.addComponent(btnLogin);
    loginBox.setComponentAlignment(logo, Alignment.TOP_CENTER);
    loginBox.setComponentAlignment(tfUsername, Alignment.TOP_CENTER);
    loginBox.setComponentAlignment(tfPassword, Alignment.MIDDLE_CENTER);
    loginBox.setComponentAlignment(cbLingue, Alignment.MIDDLE_CENTER);
    loginBox.setComponentAlignment(btnLogin, Alignment.BOTTOM_CENTER);        
}

private void doLogin() {
    try {
        tfUsername.validate();
        tfPassword.validate();
    } catch (InvalidValueException ex) {
        return;
    }
    String sessionId = getApplicationServices().getSessionId();    
    Map<String,Object> params = new HashMap<String,Object>();
    params.put("HTTP_REQUEST", VaadinService.getCurrentRequest());  //TODO Verificare se si può migliorare
    params.put("HTTP_RESPONSE",VaadinService.getCurrentResponse());
    try {
        authContext.login(sessionId, tfUsername.getValue(), tfPassword.getValue(), AuthSource.MANUAL, params);
        getApplicationServices().getCurrentUI().rebuild();
        getApplicationServices().getLanguageContext().setCurrentLanguage(getApplicationServices().getLanguageContext().getDefaultLanguage(), true);
    } catch (IllegalValueException | UserAlreadyAuthenticatedException | InvalidAccountException | InvalidPasswordException | PasswordExpiredException | UserBlockedException | LicenseNotAvailableException | UnexpectedAuthException | UIConfigurationException | LanguageException ex) {
        Window w = Dialogs.showErrorDialog("dati non validi", "Login.errorCaption.wrongData","dati non validi", "Login.errorDsc.wrongData",null);
        w.setResizable(false);
        w.addStyleName("tmpl-login-error-dialog");
        w.setWidth(20, Unit.PERCENTAGE);
    }
}

private void cambioUtente(String xpUserName) {
    if(StringUtils.isNotBlank(xpUserName)) {
        UtenteTmpl utente = utenteService.getUtenteByUserName(xpUserName);
        if(utente != null) {
            String lingua = utente.getLingua();
            cbLingue.setValue(lingua);
        }
    }
}

private void setLingua(String xpLingua) {
    Language currentLanguage = lingueMap.get(xpLingua);
    languageContext.setCurrentLanguage(currentLanguage, true);
}

protected void setLogoResource(String xpPath) {
    logo.setSource(UiUtils.getImage(xpPath));        
}

By simple test case I meant something that only contains the minimum amount of code needed to reproduce the problem, something that I can copy to my workspace and run without modifications. The code you provided has dependencies to you application and cannot be executed outside your environment.