Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

TUTORIALVaadin lets you build secure, UX-first PWAs entirely in Java.
Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Calling javascript synchronously by Enver Haase, 3 weeks ago
Doubt about addShortcutListener event
I have this code:
textValorPagamento.addShortcutListener(new ShortcutListener("Shortcut Name", ShortcutAction.KeyCode.ENTER, null) {
@Override
public void handleAction(Object sender, Object target) {
adicionarFormaPagamento();
}
});
textObsPagamento.addShortcutListener(new ShortcutListener("Shortcut Name", ShortcutAction.KeyCode.ENTER, null) {
@Override
public void handleAction(Object sender, Object target) {
adicionarFormaPagamento();
}
});
textValorTroco.addShortcutListener(new ShortcutListener("Shortcut Name", ShortcutAction.KeyCode.ENTER, null) {
@Override
public void handleAction(Object sender, Object target) {
finalizarPedido();
}
});
So I have 3 textfield in 2 when my user hit enter I execute the same method, but when I hit enter in my textValorTroco (TextField) he execute the adicionarFormaPagamento() method and not the finalizarPedido()
why?
tks
Last updated on
Hi Fabio,
if you register more than one shortcut listener for the same keys combination only the first one will be invoked.
You can add the same listener to all text fields and then discriminate over the target object
ShortcutListener action = new ShortcutListener("Shortcut Name", ShortcutAction.KeyCode.ENTER, null) {
@Override
public void handleAction(Object sender, Object target) {
if (target == textValorTroco) { finalizarPedido(); }
else { adicionarFormaPagamento(); }
}
});
textValorPagamento.addShortcutListener(action);
textObsPagamento.addShortcutListener(action);
textValorTroco.addShortcutListener(action);
HTH
Marco
Last updated on
You cannot reply to this thread.