0

Repeated code N Times

asked 2012-10-14 22:15:21 +0800

hunterbit gravatar image hunterbit
12

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?

delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest

answered 2012-10-15 08:47:07 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

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

link publish delete flag offensive edit

answered 2012-10-15 09:09:09 +0800

neillee gravatar image neillee flag of Taiwan
1692 1 5
https://plus.google.com/u...

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

link publish delete flag offensive edit

answered 2012-10-22 07:41:58 +0800

hunterbit gravatar image hunterbit
12

Thank you all.
I did not really understand how to apply the TEMPLATE to my problem. you give me an example of use?
thanks

link publish delete flag offensive edit

answered 2012-10-22 09:42:13 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

There are plenty of example for template in ZKClick here

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2012-10-14 22:15:21 +0800

Seen: 77 times

Last updated: Oct 22 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More