Multiple top-level windows and Application.terminalError

Hi! I’m having a wee bit of trouble handling errors when using multiple windows. I have two top-level windows - one unnamed, and one named “admin”, i.e. they’re at myhost/myapp and myhost/myapp/admin, respectively. When I added the admin window, I ran into problems in Application.terminalError. TerminalError displayed the caught exception in a modal dialog (some different handling depending on exception type), which was shown using

    public void terminalError(Terminal.ErrorEvent event) {
        ErrorWindow errorWindow = new ErrorWindow(event);

But of course, this doesn’t work with multiple windows. If I got an error in my admin window, the error window was shown in the main window. I don’t know the correct way of dealing with this, but some debugging led me to the following code which works in some cases. And yes, I know it’s ugly and brittle, but it works (but see below).

    public void terminalError(Terminal.ErrorEvent event) {
        ErrorWindow errorWindow = new ErrorWindow(event);

    private Window getEventWindow(Terminal.ErrorEvent event) {
        try {
            Class<? extends Terminal.ErrorEvent> eventClass = event.getClass();
            Method getComponentMethod = eventClass.getMethod("getComponent");
            if (com.vaadin.ui.Component.class.isAssignableFrom(getComponentMethod.getReturnType())) {
                com.vaadin.ui.Component component = (com.vaadin.ui.Component) getComponentMethod.invoke(event);
                Window window = component.getWindow();
                while (window.getParent() != null) {
                    window = window.getParent();
                return window;
        } catch (Exception e) {
            // Do nothing, just fall through
        return getMainWindow();

The problem I just ran into is that when the underlying exception is thrown from a handler chain which starts in a subwindow (in my case a confirm yes/no modal dialog), then the above method returns the subwindow in question (i.e. the confirm dialog), and not the top level one. This results in my error window not being shown at all. I would have thought that a subwindow would have a parent, but evidently it doesn’t. It does, however, report that it isVisible(), which means I can’t find a way of detecting that this is not the window I’m looking for.

So, after some weird code and some rambling, a question: how should I handle this? How should errors be handled in a multi-window application?

I’m using Vaadin 6.7.7.


Mats Sigge

Hello? Does anyone have some input here?

I did find one thing, and that’s in the book, in section 14.10.1 (
Exception Handling
). There’s a code snippet there, which appears to do exactly what I want. But the most interesting part, namely the mysterious method findWindowForError, is just referenced, and never defined. Google can’t find it either. So could some kind soul tell me what that method should do? Or, better yet, paste the code here. It must be defined somewhere.