Copy a component (container)


Is there some convenient way to copy a component (container) and put it in a layout, so that I could have the same component in two different layouts?

Use case:
I need to show something on the UI, but add another window for printing, where some of the UI components would be. Do I have to manually insert the same info in two places to get this to work?

// Jonas

Currently toolkit doesn’t provide way to clone components so you need to manually create views and re-set data.

One solution is to use external DataSources, multiple components can be binded to same datasource. Example: I made huge web form that was divided to several pages. And because of datasources, I could do this:

Window w = new Window();
w.addComponent(new FormPage1(MyFormPojo));
w.addComponent(new FormPage2(MyFormPojo));
w.addComponent(new FormPage3(MyFormPojo));
w.addComponent(new MyWindowPrinter());

Where each FormPage constructed new fields that binded to MyFromPojo. Code was same when initally creating new form or printing previous form. Mechanism is pretty useful for loading old pre-filled documents too. I just refresh the datasource.

Ok, thanks for the answer. It’s bit overkill in this project, but might come in handy someday.