I can't add any addShortcutListener on any TextField in Vaadin 6

Hello everybody,
I create 2 TextFields , and addShortcutListener to them …

TextField name = new TextField(“Name”);
name.addShortcutListener(new ShortcutListener(“Name”, ShortcutAction.KeyCode.ENTER, null) {
public void handleAction(Object sender, Object target) {
if(target==name){
// do my Search
}
}
});

and the second

TextField Descript = new TextField(“Description”);
Descript .addShortcutListener(new ShortcutListener(“Description”, ShortcutAction.KeyCode.ENTER, null) {
public void handleAction(Object sender, Object target) {
if(target==Descript ){
// do my Search
}
}
});

But i can’t do my search action when I press enter on the second textField… Plz ,Help :frowning:

Hi,

the generic shortcut actions (key actions)
are only supported by Window and Panel
. Please try wrapping your TextField in a Panel.

And of course, another (and maybe a better) way to do this is to add a ValueChangeListener to your TextField and set the TextField immediate. That way you’ll get a ValueChangeEvent when the user has changed the fields content and presses enter (or unfocuses the field).

-tepi

:smiley: i worked it out. .thanks so much