View Duplication on Browser Back Button Press

Hello, I did not manage to find a similar problem description on any of the forums, so I am posting it here.

I am using Navigator in my Vaadin-Spring application as stated
here
.

The problem arises when the view is changed from default to some other view and then changed back to the default (does not matter programmatically or by typing uri fragment directly in browser).

So when the default view loads, the view itself is doubled, i.e the window horizontally splits and I have two instances of the default view, and when again going to some other view and back, the previous doubled view is multiplied by 2, and so on and on…

Example:

See image attached.

Please note that it is not the case when typing the http://localhost:8080 address without any trailing /# (forward slash and hash symbols)

So the question is the following is there any workaround to get rid of /# or am I doing wrong?
Thanks.

22733.png

Could you paste your UI.init method?

MainUI class with init method.

@Theme(“mytheme”)
@SpringUI(path = “”)
public class MainUI extends UI {

@Autowired
private SpringViewProvider viewProvider;

@Override
protected void init(VaadinRequest vaadinRequest) {

       Navigator navigator = new Navigator(this, this);
       navigator.addProvider(viewProvider);

       navigator.addViewChangeListener(new ViewChangeListener() {

              @Override
              public boolean beforeViewChange(ViewChangeEvent viewChangeEvent) {
                     return true;
              }

              @Override
              public void afterViewChange(ViewChangeEvent viewChangeEvent) {
              }
      });
 }

}

Thanks. I was expecting to see something strange in how the navigator and viewprovider are configured, but they seem to be all right. I don’t know what could be the reason. Are you accidentally adding somewhere a second Navigator or adding content manually in some listener to the UI?

Just checked everything, commented out other classes with views implementation and left some for bug reproducing purposes.

[b]

  1. The MainUI is posted above.
    [/b]


2. Default view SignInView

@UIScope
@SpringView(name = “”)
public class SignInView extends VerticalLayout implements View {

@Override
public void enter(ViewChangeListener.ViewChangeEvent viewChangeEvent) {

    Notification.show("Sign In");

    setSizeFull();

    AbsoluteLayout layout = new AbsoluteLayout();
    layout.addComponent(new Button("new"), "left: 50px; top: 50px;");
    addComponent(layout);
    }

}


3. And the second view RegisterView

@UIScope
@SpringView(name = “register”)
public class RegisterView extends VerticalLayout implements View {

@Override
public void enter(ViewChangeListener.ViewChangeEvent viewChangeEvent) {
    Notification.show("Register");
}

}


4. Vaadin servlet configuration

@WebServlet(value = “/*” ,asyncSupported = true)
@VaadinServletConfiguration(productionMode = true, ui = MainUI.class)
public class VaadinServlet extends SpringVaadinServlet {
}


5. Vaadin configuration

@Configuration
@EnableVaadin
public class VaadinConfiguration {}


6. Vaadin widgetset

<?xml version="1.0" encoding="UTF-8"?>
<module>
    <inherits name="com.vaadin.DefaultWidgetSet"/>

    <inherits name="com.vaadin.addon.responsive.ResponsiveWidgetSet" />


7. WebContextInitializer (web.xml in java config)

public class WebContextInitializer implements WebApplicationInitializer {

@Override
public void onStartup(javax.servlet.ServletContext servletContext) throws ServletException {

    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.scan(WebContextInitializer.class.getPackage().getName());
    servletContext.addListener(new ContextLoaderListener(context));
    registerServlet(servletContext);
}

private void registerServlet(ServletContext servletContext) {
    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("vaadin", SpringVaadinServlet.class);
    dispatcher.setLoadOnStartup(1);
}

}

Switching forward and back between default (“”) and register (“register”) view doubles the layout on the default view.

Maybe i did something wrong in configuration?