Refreshing layouts

Hi there,
I like Vaadin and I’m developing a little demo to know its features. My demo application has two layouts: A layout for the header and another one for the body. I would like to change the body layout without changing the state of the header one. It would be something like this:


private VerticalLayout mainLayout;
private Window window;
private Layout header;
private Layout body;

public void init()
	window = new Window("My Vaadin Application");
    mainLayout = new VerticalLayout();


And when a button is pressed:


new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
body=new DemoLayout());

Is there any way to send this change to the client? I only want to refresh the body layout not the whole window. I’ve been trying to find a way to do it but no success.
Thanks in advance.


You can replace a component in your VerticalLayout by calling replaceComponent, so try:

Component newBody = new DemoLayout();
mainLayout.replaceComponent(body, newBody);
body = newBody;


Thanks Henri, that works perfectly.

is there any other way to achieve this? Thing is, that in my application architecture I don’t know at the time of switching what exactly is the old “body”, my case (clutter omitted):

public class CustomerWindow extends MyWindow { 
	protected final VerticalLayout verticalMain;
	protected Layout contentPanel;

	protected void buildContentOrdersCreate() {
		statusLabel.setCaption("Orders >> Create A New Order");
		SplitPanel sp = new SplitPanel(SplitPanel.ORIENTATION_HORIZONTAL);
		contentPanel = sp;

	protected void buildContentOrdersAll() {
		statusLabel.setCaption("Orders >> View All Orders");
		contentPanel = new SplitPanel(); 

and this is part of the code from my menubar:

		menuCommand = new Command() {

			public void menuSelected(MenuItem selectedItem) {
				CustomerWindow cw = ((CustomerWindow) myWindow);
				if (selectedItem == ordersAll) {
				} else if (selectedItem == ordersNew) {

problem is it doesn’t work this way… only by assigning a new Component to contentPanel it is not refreshed. Where to go from here?

EDIT: problem solved, my whole approach to content switching was wrong, now I reworked it from the ground, and this problem is no longer relevant