I have a modal window which calls focus() method from its constructor. This modal registers a CloseShortcut listener (e.g. ESC key) on some child input.
test 1 : Open the window from MainWindow and type ESC key => the modal window does not close itself.
test 2 : Click anywhere on modal window and type ESC key => the modal window closes itself.
Shouldn’t the focus() calling from constructor do the trick and make Application consider the modal as “active” window ?
As long as you attach (display) the window in the same request-response cycle as you create it (run it’s constructor) it should focus correctly.
If this is the case and you’re still having problems, please create a stripped down example and attach that to a new ticket about the issue at
dev.vaadin.com .
I think there is a misunderstanding here. I don’t mean that the window does not display in front of the main window. Take a look at the sampler modal window : open the modal and press the tab key => the close button should be selected, but you have to click somewhere into the modal before to get this to work.
Ah, now I understand. I think you’d need to focus a Field inside the window for the ESC-listener to fire as expected. However, I also think that focus() on the window probably should allow the key listeners to fire as expected, so please go ahead and create a ticket for this.
With Vaadin 7.5 (current BETA) I have tried several Threading implementations. None worked. Could you please post a working code snipped! Thanks in advance!
I am currently in Vaadin 7.4 and I am having a similar issue. When the window loads, I want focus to go to the first field on the page, but it doesn’t work. I can see that the window does try to give the first field focus, but it only lasts about .1 seconds, at which point the focus disappears completely. Worse, pressing Tab doesn’t send the focus anywhere either … not at all sure where the focus is.
I have tried the threaded method mentioned, and that didn’t work either. What’s going on? This is very important because my app needs to work with minimal mouse involvement.
Side note: This doesn’t work on any of my windows any longer. However, at some point in the past, this did work. Not sure when it stopped working, but my guess is that it broke when upgrading from 7.3 to 7.4.
Sorry to be a pain, but this is becoming quite a problem for me. The client insists that this application be fully functional without a keyboard, so maintaining focus when windows open is a must. Currently, none of my windows get any focus, and so everything I have tried so far has gotten me nowhere. The best I can do is get it so that I can see the field get focus for 1/10 of a second, but then it disappears into the void.
Any thoughts? Suggestions? Change of approach? Should I avoid Windows altogether?
Thanks Johannes, but that didn’t help. It still does exactly the same thing. I reviewed the ticket, and it seems like it was accepted 6 days ago, so maybe there will be a fix for this soon.
i think you may have the error at another place, because it is working properly in the following example.
Maybe you could post me a minimum sample of your code.
working example:
[code]
Button button = new Button(“open window”);
button.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
Window window = new Window();
window.setModal(true);
TextField textField = new TextField("focus me");
window.addFocusListener(new FocusListener() {
@Override
public void focus(FocusEvent event) {
textField.focus();
}
});
window.setContent(textField);
UI.getCurrent().addWindow(window);
}
});
[/code]broken example:
Button button = new Button("open window");
button.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
Window window = new Window();
window.setModal(true);
TextField textField = new TextField("focus me");
window.setContent(textField);
UI.getCurrent().addWindow(window);
textField.focus();
}
});
Interesting, when I implemented the focus listener the way you specified, it works. Previously, my window simply implemented FocusListener and I overrided the focus function within my window, which didn’t work. Not sure why your way worked and my way didn’t, but I appreciate your help immensely.
I tried this on other windows as well, and they are all now getting focus. It is funny to note, though, that the focus flickers in the beginning. It seems that my previous function for getting focus is firing, then it goes away, then it comes back. Odd behavior, sure, but functional.