com.vaadin.ui.Panel#replaceComponent problem

Hi,

I have a problem with replaceComponent in Panel.

I used source from your examples (http://demo.vaadin.com/sampler/#RichTextEditor) and everything works fine with VerticalLayout but I change it to Panel then it does not work.

Could you tell me what am I doing wrong?

public class SwitchTest extends Panel implements ClickListener {

	private final Button b;
	private final Label richText;

	private final RichTextArea editor = new RichTextArea();

	public SwitchTest() {

		richText = new Label("<h1>Rich text example</h1>" + "<p>The <b>quick</b> brown fox jumps <sup>over</sup> the <b>lazy</b> dog.</p>"
				+ "<p>This text can be edited with the <i>Edit</i> -button</p>");
		richText.setContentMode(Label.CONTENT_XHTML);

		addComponent(richText);

		b = new Button("Edit");
		b.addListener(this);
		addComponent(b);

		editor.setWidth("100%");
	}

	@Override
	public void buttonClick(ClickEvent event) {
		if (getComponentIterator().next() == richText) {
			editor.setValue(richText.getValue());
			replaceComponent(richText, editor);
			b.setCaption("Apply");
		} else {
			richText.setValue(editor.getValue());
			replaceComponent(editor, richText);
			b.setCaption("Edit");
		}
	}

}

That code works for me; what Vaadin version are you using?

I use 7.0.0.beta1 version.

OK, I found the problem: The implementation of getComponentIterator() has changed between V6 and V7. A Panel is not a layout in itself: it always contains something (which is a VerticalLayout by default). In Vaadin6, the panel simply forwarded the calls to the content, but in V7 the Panel actually processes them itself.

So, to fix this, you should call getContent().getComponentIterator() instead. Or, alternatively, you can check if richText is attached by checking if its parent is null.