Help with CssLayout

Hi all! I’m using a CssLayout as container for my views. When i navigate view by view i would change the content of my template so i use the function setContent:

public void setContent(Component view){
contentArea.removeAllComponents();
contentArea.addComponent(view);
}

This doesn’t work infact i can’t see nothing in the page, but if i delete the removeAllComponents function i can see the first content and only the first even if i change view.
Can someone help me?
Thank u :slight_smile:

//////////////////////////////////////////// the full class: /////////////////////////////////////////

@SpringUI
@UIScope
public class MotorClickTemplate extends HorizontalLayout {

private static final long serialVersionUID = 4514153457724275485L;
CssLayout contentArea = new CssLayout();
CssLayout menuArea = new CssLayout();
Component menu;

@PostConstruct
public void initMotorClickTemplate() {
    setSizeFull();
    setSpacing(true);
    setMargin(new MarginInfo(true,true,true,true));
    menuArea.setPrimaryStyleName("valo-menu");
    contentArea.setPrimaryStyleName("valo-content");
    contentArea.addStyleName("v-scrollable");
    contentArea.setSizeFull();

    addComponents(menuArea, contentArea);
    setExpandRatio(contentArea, 1);
}

public ComponentContainer getContentContainer() {
    return contentArea;
}

public void setMenu(final Component menu) {
    if (this.menu != null) {
        menuArea.removeComponent(this.menu);
    }
    menu.addStyleName("valo-menu-part");

    this.menu = menu;
    menuArea.addComponent(this.menu);
}

public void setContent(Component view){
    contentArea.removeAllComponents();
    contentArea.addComponent(view);
}

}

Hi Marco,

can you maybe provide a full-working example (e.g. via github)?
Also I would suggest using the @SpringView-functionality to implement different views. You will be able to access them by URL and skip many things you’d have to implement on your own with your approach.

See the Vaadin-Spring Tutorial:

http://vaadin.github.io/spring-tutorial/#_spring_views

You can also find a nice and working example in the vaadin4spring addon:

https://github.com/peholmst/vaadin4spring/tree/master/samples/sidebar-sample

You can skip the sidebar-component if you don’t need it.

Hi Samuel,
I will use the spring view functionality as u said. it is better for what i need.
Thanks man :slight_smile: