Browser navigation with sub-window open

My vaadin application exhibits strange behavior:

With a modal sub-window open I still can use the browsers back and forth buttons and the navigation views under the window change. Any ideas how to circumvent this behavior?

Use a view change listener to check if there are open modal windows:

getUI().getNavigator().addViewChangeListener(new ViewChangeListener() {
    @Override
    public boolean beforeViewChange(ViewChangeEvent event) {
        Collection<Window> windows = getUI().getWindows();
        for (Window window : windows) {
            if(window.isModal()) {
                return false;
            }
        }
        return true;
    }
            
    @Override
    public void afterViewChange(ViewChangeEvent event) {}
});

Hallo Max -

Thanks for your quick help. I experimented with your suggestion.

It works fine for surpressing the navigation change, but seems to bring the history out of sync. If I go back in history, the url at the top still changes, only the view does not adjust accordingly. The history then continues with the new url, e.g. it goes two views back instead of one.

I guess this is better than before, but rather ugly.

Best,
Timo

We did some more testing and sometimes we receive now the following exception:

SEVERE:
java.lang.IllegalArgumentException: Trying to navigate to an unknown state ‘’ and an error view provider not present
at com.vaadin.navigator.Navigator.navigateTo(Navigator.java:528)
at com.vaadin.navigator.Navigator$UriFragmentManager.uriFragmentChanged(Navigator.java:141)
at sun.reflect.GeneratedMethodAccessor156.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:508)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:198)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:161)
at com.vaadin.server.Page.fireEvent(Page.java:603)
at com.vaadin.server.Page.updateLocation(Page.java:979)
at com.vaadin.ui.UI.doRefresh(UI.java:694)
at com.vaadin.server.communication.UIInitHandler.reinitUI(UIInitHandler.java:269)
at com.vaadin.server.communication.UIInitHandler.getBrowserDetailsUI(UIInitHandler.java:176)
at com.vaadin.server.communication.UIInitHandler.synchronizedHandleRequest(UIInitHandler.java:74)
at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41)
at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1402)
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:305)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at eu.contecht.globld.his.filters.LoggingFilter.doFilter(LoggingFilter.java:44)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:534)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1081)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)

We cannot reproduce this yet … will keep on working on it!

Any updates here?

        Collection<Window> windows = getUI().getWindows();
        //Transform Collection to array
        Object windowArray = windows.toArray();
        //Loop for the array
        int j;
        Window window;
        for(j=0; j<windowArray.length; j++){
            window = (Window) windowArray[j]
;
         }