do i understand this right?

hello

i create a custom composite in vaadin 7 and try to use it.
after hours and a lot of errors i realize that i should not edit the @AutoGenerated Methods for
using the visual editor with no errors :*)

so i have this class:

public class TestComposite extends CustomComponent {

	/*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

	@AutoGenerated
	private AbsoluteLayout mainLayout;
	@AutoGenerated
	private ComboBox comboSelector;
	/**
	 * The constructor should first build the main layout, set the
	 * composition root and then do any custom initialization.
	 *
	 * The constructor will not be automatically regenerated by the
	 * visual editor.
	 */
	public TestComposite() {
		buildMainLayout();
		setCompositionRoot(mainLayout);

		// TODO add user code here
		
	}

	@AutoGenerated
	private AbsoluteLayout buildMainLayout() {
		// common part: create layout
		mainLayout = new AbsoluteLayout();
		mainLayout.setImmediate(false);
		mainLayout.setWidth("100%");
		mainLayout.setHeight("100%");
		
		// top-level component properties
		setWidth("100.0%");
		setHeight("100.0%");
		
		// comboSelector
		comboSelector = new ComboBox();
		comboSelector.setCaption("Auswahl");
		comboSelector.setImmediate(false);
		comboSelector.setWidth("-1px");
		comboSelector.setHeight("-1px");
		mainLayout.addComponent(comboSelector, "top:20.0px;left:22.0px;");
		
		return mainLayout;
	}

}

the question now is, where do i add my own code? like this one comboSelector.addItem("hi");

is this the right way?


public class TestComposite extends CustomComponent {

	/*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

	@AutoGenerated
	private AbsoluteLayout mainLayout;
	@AutoGenerated
	private ComboBox comboSelector;
	/**
	 * The constructor should first build the main layout, set the
	 * composition root and then do any custom initialization.
	 *
	 * The constructor will not be automatically regenerated by the
	 * visual editor.
	 */
	public TestComposite() {
		buildMainLayout();
		setCompositionRoot(mainLayout);

		// TODO add user code here
		[b]
[color=#fc0505]
comboSelector.addItem("hi");
[/color]
[/b]
	}

	@AutoGenerated
	private AbsoluteLayout buildMainLayout() {
		// common part: create layout
		mainLayout = new AbsoluteLayout();
		mainLayout.setImmediate(false);
		mainLayout.setWidth("100%");
		mainLayout.setHeight("100%");
		
		// top-level component properties
		setWidth("100.0%");
		setHeight("100.0%");
		
		// comboSelector
		comboSelector = new ComboBox();
		comboSelector.setCaption("Auswahl");
		comboSelector.setImmediate(false);
		comboSelector.setWidth("-1px");
		comboSelector.setHeight("-1px");
		mainLayout.addComponent(comboSelector, "top:20.0px;left:22.0px;");
		
		return mainLayout;
	}

}

or how i should add my own code to be able to use the editor without errors?

thanks
isa

Yes.

In most cases, you would either want to create a separate method that is called from the constructor to do all your initialization or create new methods that expose a suitable API for the visually edited component and then call them from the constructor or from outside the class.

hello henri

thanks for your answer !

isa