GWT KeyPress过滤器

Mat*_* B. 0 java gwt keypress filter

你如何创建KeyPress过滤器,在文本字段中仅强制数字作为输入.像这样的东西:http:
//www.smartclient.com/smartgwt/showcase/#form_keypress_filter

添加anoyence有没有办法在uiBinder xml文件中执行此操作?

jon*_*asr 6

这里描述了执行操作的代码.

在您的uiBinder文件中,定义TextBox项.

<g:TextBox uifield='textBox'/>
Run Code Online (Sandbox Code Playgroud)

在您的课程中,您可以直接添加KeyPressHandler,例如:

textBox.addKeyPressHandler(new KeyPressHandler() {

        @Override
        public void onKeyPress(KeyPressEvent event) {
            if (!"0123456789".contains(String.valueOf(event.getCharCode()))) {
                textBox.cancelKey();
            }
        }

    });
Run Code Online (Sandbox Code Playgroud)

或者您可以像这样使用@UiHandler注释:

@UiHandler("testBox")
public void onKeyPress(KeyPressEvent event) {
    if (!"0123456789".contains(String.valueOf(event.getCharCode()))) {
        textBox.cancelKey();
    }
}
Run Code Online (Sandbox Code Playgroud)