0

I need a customized TextArea component, where I'd like disable some keys (f.e. backspace and del keys). For this I created a vaadin-archetype-widget artifact, and I created two subclasses (MyTextArea and VMyTextArea), and I overrode the onKeyDown method in class VMyTextArea:

@Override
public void onKeyDown(KeyDownEvent event) {
    int kc = event.getNativeKeyCode();
    if (kc == KeyCodes.KEY_BACKSPACE || kc == KeyCodes.KEY_DELETE) {
        return;
    }
    super.onKeyDown(event);
}

Unfortunately this solution doesn't solve my problem, the backspace and delete keys work normally. My question how to do this?

4

1 回答 1

1

解决方案:

public class VMyTextArea extends VTextArea {

    VMyTextArea() {
        super();
        addKeyDownHandler(new KeyDownHandler() {
            public void onKeyDown(KeyDownEvent event) {

                int kc = event.getNativeKeyCode();
                if (kc == KeyCodes.KEY_BACKSPACE || kc == KeyCodes.KEY_DELETE) {
                    event.preventDefault();
                }
            }
        });

    }
}
于 2012-10-21T20:48:58.017 回答