-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hello to all.
I have a problem with the dynamic generation of code in a page ZUL.
I have a page with the following code
<?page title="Prova ZUL" contentType="text/html;charset=UTF-8"?> <zk> <window title="Prova N Volte ZUL" border="normal"> <spinner /><button label="OK" onClick="" /> </window> </zk>
and I insert a number that indicates my reps and when I press the button ok I would like to generate the following code.
<?page title="Prova ZUL" contentType="text/html;charset=UTF-8"?> <zk> <window title="Prova N Volte ZUL" border="normal"> <spinner /><button label="OK" onClick="" /> <vlayout height=""> <!-- START Dynamically generated code --> <hlayout height=""> <combobox id="cmb1"><comboitem label=""/><comboitem label=""/></combobox> Name <textbox /> </hlayout> <hlayout> <combobox id="cmb2"><comboitem label=""/><comboitem label=""/></combobox> Name <textbox /> </hlayout> <hlayout> <combobox id="cmb3"><comboitem label=""/><comboitem label=""/></combobox> Name <textbox /> </hlayout> <!-- END Dynamically generated code --> </vlayout> </window> </zk>
How can I make the code I wanted to be repeated N times?
If you are familiar with ZK what you can do...Create a Div or window below your Button and Wire that component with Java Class. And in Java class call a Method When user press Ok Button and this Method will add other component inside the Window or Div tag like Vlayout,Hlayout,Combobox etc. and when page loaded hide the Div and Window when user click on Ok Button at that time this will be visible..
thanks
Hello hunterbit,
There are several ways you can use to achieve this. Generating the component tree structure using Java code is one way, which is illustrated below.
You may want to check out children binding for some other ideas.
<window title="Dynamically Generate Compoents" border="normal"> <spinner id="reps" /> <button label="OK"> <attribute name="onClick"> <![CDATA[ Component comp = reps.getParent().getLastChild(); if (comp instanceof Vlayout) { comp.detach(); } Vlayout v = new Vlayout(); for (int i=1; i <= reps.getValue(); i++) { Hlayout h = new Hlayout(); Combobox c = new Combobox(); c.setId("cmd" + i); c.setParent(h); h.setParent(v); } v.setParent(reps.getParent()); ]]> </attribute> </button> </window>
Neil Lee, Engineer
Potix Corporation
There are plenty of example for template in ZKClick here
Asked: 2012-10-14 22:15:21 +0800
Seen: 77 times
Last updated: Oct 22 '12