TextField that catches enter-press

Hi,

I’ve been trying to make a TextField that catches an enter-press. I’m developing it for login now, but might use it elsewhere. However, I’m having trouble. I can catch the presses fine with my code, but the “secret” variable doesn’t work with my code, everything is echoed back normally. Is there an easier alternative or can you point out what’s wrong with my code?


public class VEnterCatchingTextField extends VTextField {
    
    @SuppressWarnings("deprecation")
    public VEnterCatchingTextField() {
        addKeyboardListener(new KeyboardListenerAdapter() {

            @Override
            public void onKeyPress(Widget sender, char keyCode, int modifiers) {
                if (keyCode == KeyboardListener.KEY_ENTER) enterPressed();
            }
        });
    }
    
    public void enterPressed() {
        client.updateVariable(id, "enterPressed", true, true);
    }
}

public class EnterCatchingTextField extends TextField {

    private static final long serialVersionUID = 1L;

    @SuppressWarnings("unchecked")
    @Override
    public void changeVariables(Object source, Map variables) {
        super.changeVariables(source, variables);
        if (variables.containsKey("enterPressed")) {
            // do stuff here
        }
    }
    
    @Override
    public String getTag() {
        return ("entercatchingtextfield");
    }
}

Here is an example on how to do this completely on server-side:
http://dev.vaadin.com/svn/incubator/paymate-security-demo/src/com/paymate/vaadin/LoginDialog.java

You might also consider using
http://vaadin.com/api/com/vaadin/ui/LoginForm.html
as it allows the browsers to autofill the passwords.