Posts

Showing posts from June, 2014

Vaadin 7: Detect Enter Key in a TextField

Vaadin 7: Detect Enter Key in a TextField This can be easily achieved just by adding a shortcutlistener whenever the TextField gets the focus and remove it when it blurs. From an IOC perspective wrapping the TextField would most probably result in less rework than extending the TextField: For example: TextField myTextField = new TextField("A text field"); myTextField.setImmediate(true); OnEnterKeyHandler onEnterHandler=new OnEnterKeyHandler(){             @Override             public void onEnterKeyPressed() {                  Notification.show("V oight Kampff Test ",                     Notification.Type.HUMANIZED_MESSAGE);             }         }; onEnterHandler.installOn(myTextField); ------------------------------------------------------------------- And the code for OnEnterKeyHandler is: import com.vaadin.event.FieldEvents; import com.vaadin.event.ShortcutAction; import com.vaadin.event.ShortcutListener; import com.vaadin.ui.TextField; p