Hello! I’m having a pretty frustrating issue here. I’m not sure what I’m missing exactly, and nothing I’ve found has helped.
When I navigate from view to view, instead of “swapping out”, each individual page’s contents just start stacking under each other. I’ve attached an image to illustrate my issue.
Each of those panels is actually components from different View classes. If you where to hit the “home” button, the URI would change, but it would create a fourth stacked panel at the bottom saying “This is my Default Label”. Why is this happening? I have changed relatively very little about the spring-tutorial code that Vaadin provides, but now this is happening. Any insight is appreciated.
MyUI.java
package org.vaadin.spring.tutorial;
import com.vaadin.annotations.Theme;
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewDisplay;
import com.vaadin.server.VaadinRequest;
import com.vaadin.spring.annotation.SpringUI;
import com.vaadin.spring.annotation.SpringViewDisplay;
import com.vaadin.ui.*;
import com.vaadin.ui.themes.ValoTheme;
@Theme("valo")
@SpringUI
@SpringViewDisplay
public class MyUI extends UI implements ViewDisplay {
final VerticalLayout MY_WINDOW = new VerticalLayout();
@Override
protected void init(VaadinRequest request) {
MY_WINDOW.setSizeFull();
setContent(MY_WINDOW);
final CssLayout topBar = new CssLayout();
for (String[] s: new String[]
[]{{"UI","ui"}, {"View","view"}, {"Home",""}, {"Login","login"}}) {
topBar.addComponent(this.createNavigationButton(s[0]
, s[1]
));
}
MY_WINDOW.addComponent(topBar);
}
private Button createNavigationButton(String caption,
final String viewName) {
Button button = new Button(caption);
button.addStyleName(ValoTheme.BUTTON_SMALL);
// If you didn't choose Java 8 when creating the project, convert this
// to an anonymous listener class
button.addClickListener(
event -> getUI().getCurrent().getNavigator().navigateTo(viewName));
return button;
}
public void showView(View view) {
MY_WINDOW.addComponent((Component) view);
}
}