All components are cloneable. In other words, they are implemented java.lang.Cloneable. Thus, it is simple to replicate components as follows.
<vbox id="vb"> <listbox id="src" multiple="true" width="200px"> <listhead> <listheader label="Population"/> <listheader align="right" label="%"/> </listhead> <listitem value="A"> <listcell label="A. Graduate"/> <listcell label="20%"/> </listitem> <listitem value="B"> <listcell label="B. College"/> <listcell label="23%"/> </listitem> <listitem value="C"> <listcell label="C. High School"/> <listcell label="40%"/> </listitem> </listbox> <zscript> int cnt = 0; </zscript> <button label="Clone"> <attribute name="onClick"> Listbox l = src.clone(); l.setId("dst" + ++cnt); vb.insertBefore(l, self); </attribute> </button> </vbox>
Once a component is cloned, all its children and descendants are cloned, too.
The cloned component doesn't belong to any page and parent. In other words, src.clone().getParent() returns null.
ID is not changed, so you remember to change ID if you want to add it back to the same ID space.