Enter as a shortcut key

Hi

I’m evaluating Vaadin and I’m trying to create a simple searching gui for an already existing application. I have a page with a search form and a table that lists the results. I have a query object that I bind to the form. When user presses search button, the table is updated with the results.

It would be really great if pressing enter when editing the form would “click” the button. Before you direct me to the shortcut part in the Vaadin book, I already found it. The problem is that pressing enter doesn’t actually click the button. Can anyone spot what I’m doing wrong?

        Button searchButton = new Button("Hae");
        searchForm.getFooter().addComponent(searchButton);
        searchButton.setClickShortcut(KeyCode.ENTER);
        searchButton.addListener(new Button.ClickListener() {
                @Override
                public void buttonClick(ClickEvent event) {
                    fillTable();
                }
            });
        searchButton.setStyleName("primary");

Hi Toni,

I tried this out with basically identical code to your code snippet and it worked as expected. Without any more details it’s hard to say where the problem is. Are you sure the
buttonClick
method is not run when you press enter?

  • Teemu

I tried debugging. The buttonclick gets called when using mouse but not on enter. If this is supposed to work then I’ll try looking if something else is wrong :slight_smile:

Hi, I’m experiencing the same issue. I added to my existing application the following line

searchBtn.setClickShortcut(KeyCode.ENTER);

and nothing happens when I press ENTER…

just tried a test case…

package com.example.enter;

import com.vaadin.Application;
import com.vaadin.event.ShortcutAction.KeyCode;
import com.vaadin.ui.*;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;

public class EnterApplication extends Application {
@Override
public void init() {
final Window mainWindow = new Window(“Enter Application”);

	Form f = new Form();		
	Button btn = new Button("Click me", new ClickListener() {
		@Override
		public void buttonClick(ClickEvent event) {
			mainWindow.showNotification("Button was triggered");
		}
	});
	btn.setClickShortcut(KeyCode.ENTER);
	
	/*
	 * these dont work
	 */
	//f.getFooter().addComponent(btn);
	//mainWindow.addComponent(f);
	
	/*
	 * this one does
	 */
	mainWindow.addComponent(btn);
	
	setMainWindow(mainWindow);
}

}

from the comments you can see that the clicklistener wont fire when the btn is added to the form’s footer.

Do you get the same results?

Hi,

Please update to the latest bugfix version and your problem is solved.

See:
http://dev.vaadin.com/ticket/5341

cheers,
matti

I’m experiencing problems with .setClickShortcut.

I have my class, which in the end creates some object which draws a button which does some action when clicked. I have an action associated with it using .setClickShortcut(KeyCode.ENTER). I have several instances of this object instantiated, but the associated keypress only works on the 1st instance of this button.

Note that there should be no “confussion” on which button should be “fired” when pressing enter because my different instances of the object are distributed across different tabs, so there’s only one single different button visible each time.

Am I using this improperly? Maybe should I do this ClickShortcut setting explicitly to the button each time I change the visible/active tag?

We’ve not re-tried in over a year (Vaadin 7), but we had to disable our use of this for our multi-tab app as well. It seems that even though the other tabs are not visible, they were all still somehow active. So it worked for a single view app, but less so when wanting it to work per “Form” in a tabbed UI.

Thanks for your report, David. I’m on Vaadin 7, also.

I’ll try to explicitly enable/disable the key shortcut when entering/exiting the tab then. We’ll see if it works…