Extending VWindow client Widget

I have a requirement to capture the key up/down events on the Window object when it is focused. I was trying that to do that by extending the VWindow client side widget like

public class VCustomWindow extends VWindow {


And then using this widget on my window class like

public class MyWindow extends Window {


But when I do this, I do not see any thing in the browser screen and there is no error on client or server.

Can anybody suggest what is wrong when I use this VWindow extended. I have tried other extensions like VPanel & VFilterSelect and I was successfully able to do that.

Can anybody suggest any other solution to capture the key up/down events when the window is currently focused?

ShortcutActions may be the thing you are looking for. On the server side:

window.addActionHandler(new Handler() {
	private ShortcutAction upAction;
	private ShortcutAction downAction;

	public Action[] getActions(Object target, Object sender) {
		upAction = new ShortcutAction(null, KeyCode.ARROW_UP, null);
		downAction = new ShortcutAction(null, KeyCode.ARROW_DOWN, null);
		return new Action[]{upAction, downAction};
	public void handleAction(Action action, Object sender, Object target) {
		if(action == upAction){
		} else if(action == downAction){

Thanks Jens, I am aware of this approach but if I use this, I will have to register each and every key in the keyboard in order to get the handleAction to be called. Is there a way to register any key pressed in this scenario?

Note that VWindow is used for subwindows only, VView is the equivalent for top-level windows.

Having top-level windows and subwindows share the server side code but not client side code is messy and results in bad APIs on the server side, so this will change in future versions, probably Vaadin 7.

Still, do you need to capture so many different key events that shortcuts are not convenient?

Hi Henri,
If I add Shortcut action for characters like A-Za-z 0-9 etc then because action is registered for these characters, I am no longer able to type any character in the text field for example. So I have a requirement for capturing which key was pressed as well as be able to type those normal characters. How can I achieve this?


If you need unmodified (no ALT/CTRL, …) keys as shortcuts and have text components, you might indeed have to customize VView.
It is created with GWT.create() so replacing it with GWT deferred bindings should work.

Unfortunately I cannot give details on how to do this in your case - if you have problems with it, maybe someone else can give more pointers about this.

I implemented this this week. The key was to create a custom client side implementation out of VView. Because the main window is a special case of “widget”, a standard @ClientWidget annotation was not enough. Instead you had to use GWT’s deferred binding feature. That is, in you widgetset xml, you define this:

<replace-with class="com.vaadin.CustomWindow">
    <when-type-is class="com.vaadin.terminal.gwt.client.ui.VView"/>

with the custom window in place, it was a matter of override onBrowserEvent, where all browsers event pass, as well as keystrokes. Send those events to the server and you’re done.

Thanks Jens, this worked for me.