replaceComponent()

Trying to use replaceComponent() to remove one VerticalLayout from the root component and replace it with another from another view, as described
here
. My code below does not replace the layout, but adds to it, so that the oldLayout is displayed, followed by the newLayout. Any thoughts to share? All is appreciated.

My code…

    VerticalLayout oldLayout = userView.getLayout();
    VerticalLayout newLayout = new VerticalLayout(); 
    newLayout.addComponent(userView.setupLayout(userView.updateList()));
    userView.getRootComponent().replaceComponent(oldLayout, newLayout);
    oldLayout = newLayout;

Hi,

just a thought, looking at the
javadocs of the replaceComponent
method:

This method replaces component with another one is such way that the new component overtakes the position of the old component. If the old component is not in the container, the new component is added to the container. so maybe the rootComponent isn’t the one you want? Could even be that the rootComponent is the same as the one returned by getLayout(), so you’re basically writing oldLayout.replaceComponent(oldLayout, newLayout), which would just add the newLayout to the root layout of your userView.

I did a quick simple test with replaceComponent and it seems to work as advertised.

-Olli