Swapping a component between 2 Winodws

This is probably a difficult one… sorry.

I’m trying to remove a component from the main window to move it to a modal window. Then I move it back to the main window.
I’ve an example that works and another that fails.

Basically, when moving from the main window to the modal:

  1. instantiate new Window (modal)
  2. mainWindow.removeComponent
  3. modal window .setContent of my component

When moving back from the modal to the main, I do:

  • modal window .setContent(null)
  • mainWindow.addComponent( my component )

It works fine, except when I change the last step:
If I put the component inside a Layout (itself inside the mainWindow), then the component does not come back to the main Window.
So, subLayout.addComponent( my component) does not work, while mainWindow.addComponent( my component ) works.

I’ve no hell idea why :frowning:
Does somebody know?

Here is the full code if you want to reproduce: the first case works, the second is very similar but does not work.

package com.example.vaadintest2;

import com.vaadin.Application;
import com.vaadin.ui.Button;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;

public class Vaadintest2Application extends Application {
	
	Window modalWindow = null; 
	Window modalWindow2 = null;
	
	
	@Override
	public void init() {
		final Window mainWindow = new Window("Vaadintest2 Application");
		Label label = new Label("Hello Vaadin user");
		mainWindow.addComponent(label);
		setMainWindow(mainWindow);

		
		// 1111111111111
		// This can move forth and back.
		final HorizontalLayout movingContainer = new HorizontalLayout();
		movingContainer.addComponent(new Label("I can move to a form and back"));
		movingContainer.addComponent(new Button("click me", new ClickListener() {

			public void buttonClick(ClickEvent event) {
				if (modalWindow == null) {  // label not yet in modal window
					modalWindow = new Window();
					modalWindow.setModal(true);
					mainWindow.removeComponent(movingContainer);
					modalWindow.setContent(movingContainer);
					mainWindow.addWindow(modalWindow);     // DIFFERENCE
				} else {  // label already in modal window => we close.
					modalWindow.setContent(null);
				    mainWindow.removeWindow(modalWindow);
				    modalWindow = null;
				    mainWindow.addComponent(movingContainer);  // DIFFERENCE
				}
			}
		}));
		
		mainWindow.addComponent(movingContainer);  // DIFFERENCE
		
		
		
		// 22222222222 
		final VerticalLayout vLayout = new VerticalLayout();
		mainWindow.addComponent(vLayout);
		
		// This can move to the form but can not come back to the main window.
		final HorizontalLayout movingContainer2 = new HorizontalLayout();
		movingContainer2.addComponent(new Label("I can move to a form but NOT back"));
		movingContainer2.addComponent(new Button("click me 2", new ClickListener() {

			public void buttonClick(ClickEvent event) {
				if (modalWindow2 == null) {  // label not yet in modal window
					modalWindow2 = new Window();
					modalWindow2.setModal(true);
					vLayout.removeComponent(movingContainer2);  // DIFFERENCE
					modalWindow2.setContent(movingContainer2);
					mainWindow.addWindow(modalWindow2);
				} else {  // label already in modal window => we close.
					modalWindow2.setContent(null);
				    mainWindow.removeWindow(modalWindow2);
				    modalWindow2 = null;
				    vLayout.addComponent(movingContainer2);   // DIFFERENCE
				}
			}
		}));
		
		vLayout.addComponent(movingContainer2);   // DIFFERENCE
	}

}

Hi John,

This actually seems to be a refreshing problem. For some reason the changes in the vLayout are not sent to the client. If you refresh the page after the modal window has been closed the component appears where it should be.

It’s clearly a bug in Vaadin. I filed a ticket with your testcase at
#3132
. Bump the ticket if it’s high priority for you.

/Jonatan

I closed the ticket as I cannot reproduce the problem with the latest development version. Please test the latest nightly to see if it is fixed.