Auto-Opening window from view

I have a view which displays a table of search results. When the view is navigated to, i need to automatically open the search window (a simple vaadin window). I can open it ok from a button on the view BUT it want to auto-show it when the view displays… any ideas?

Hi,

You can override the [View::enter]
(https://vaadin.com/api/com/vaadin/navigator/View.html#enter-com.vaadin.navigator.ViewChangeListener.ViewChangeEvent-) method and put the logic to show the window there.

I tried the following previously without success:-

@Override
public void enter(final ViewChangeEvent event) {    	    	
	UI.getCurrent().addWindow(searchWindow);    	
}

Any other ideas?

It should work. At least the following works:

public class VaadinUI extends UI {

    public static class View1 extends VerticalLayout implements View {
        @Override
        public void enter(ViewChangeListener.ViewChangeEvent event) {
            Window window = new Window("Window", new Label("It works!"));
            UI.getCurrent().addWindow(window);
        }
    }

    @Override
    protected void init(VaadinRequest vaadinRequest) {
        Navigator navigator = new Navigator(this, this);
        navigator.addView("", View1.class);
    }

}

Did you get an exception or anything else you can share?

Thanks for your attention to this, its much appreciated. The application is based on the DashBoard Demo app.

My view is declared as follows:-

@SuppressWarnings({ “serial”, “unchecked” })
public final class SearchTransactionsView extends VerticalLayout implements View {

@Override
public void enter(final ViewChangeEvent event) {    	   
	System.out.println("Enter begin");
	Window window = new Window("Window", new Label("It works!"));
    UI.getCurrent().addWindow(window);
	System.out.println("Enter end");
}

}

The message is printed, by the window simply doesn’t display (nothing happens, no error).
Enter begin
Enter end

Any ideas?

Are you able to share a project I can easily run to try to reproduce the issue?

If you take the vaadin quicktickets demo project and edit the transactions view, this simulates the issue.

Thanks. I was able to reproduce the issue. Seems like an issue in the Framework. Could you please file a new issue at https://github.com/vaadin/framework/issues? Duplicating the line that adds the window seems to fix the problem:

@Override
public void enter(final ViewChangeEvent event) {
    Window window = new Window("Window", new Label("Attach!"));
    UI.getCurrent().addWindow(window);
    UI.getCurrent().addWindow(window); // workaround
}

Thanks, when i try this workaround i get:-

java.lang.IllegalArgumentException: Window is already attached to an application.

I am using Vaadin 7.6.8

Ok, I was using 8.0.1.

It appears that the issue is caused by the event bus listening to the closeopenwindows event…

Commenting the following lines allows me to open the window on enter as expected:-

@Subscribe
public void closeOpenWindows(final CloseOpenWindowsEvent event) {
//for (Window window : getWindows()) {
// window.close();
//}
}