0

combobox databinding only shows on item

asked 2010-05-04 23:48:44 +0800

guest123 gravatar image guest123
12

updated 2010-05-04 23:49:02 +0800

The code below only shows on item... I need it to show all elements in tmp. any idea? thanks
<zscript>
List tmp=Arrays.asList(new String[]{"a","b","c"});
]]>
</zscript>


<combobox id="mycb" model="@{tmp}">
<comboitem self="@{each=row}" label="xxx" value="yyy">
</comboitem>
</combobox>

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2010-05-05 08:16:45 +0800

tmillsclare gravatar image tmillsclare
799 2 5 30

I answered you here :).

link publish delete flag offensive edit

answered 2010-05-05 12:40:54 +0800

guest123 gravatar image guest123
12

thank you!
what if I have a list/array where each element is an array of two object, the first one represents label, the second one represents value. I tried <comboitem self="@{each=row}" label="@{row[0]}" value="row[1]"> not working.

link publish delete flag offensive edit

answered 2010-05-05 21:18:49 +0800

tmillsclare gravatar image tmillsclare
799 2 5 30

updated 2010-05-05 21:19:29 +0800

Hey guest123,

There are two ways. The first way is the easiest. I would not have an array but use a POJO instead following the Javabean conventions. This would allow easy access. For example:

<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?> 
<zk>
  <zscript>
	  <![CDATA[
		  public class MyItem {
			  private String _label;
			  private String _value;
			  
			  public String getLabel() {
				  return _label;
			  }
			  
			  public void setLabel(String label) {
				  this._label = label;
			  }
			  
			  public String getValue() {
				  return _value;
			  }
			  
			  public void setValue(String value) {
				  this._value = value;
			  }
		  }
		  
		  final MyItem[] itemArray = new MyItem[5];
		  
		  for(int i=0; i<itemArray.length; i++) {
			  itemArray<i > = new MyItem();
			  itemArray<i >.setLabel("Label: " + i);
			  itemArray<i >.setValue("Value: " + i);
		  }
		  
	  ]]>
  </zscript>
  <combobox id="list" width="200px" model="@{itemArray}">
  	<comboitem self="@{each='item'}" label="@{item.label}" value="@{item.value}" />
  </combobox> 
</zk>

Secondly you could use a Comboitem renderer. They are very good when you want to create more complex interfaces. If you are stuck on how to use it try searching for RowRenderer and this should give you an idea.

Third, if you are creating a large application, take a look at using the MVC pattern over ZScript. It offers a performance boost as it is pre-compiled. Here is a tutorial. There are more though, just do a search for ZK MVC in Google.

Lastly, please can you accept my answer on Stackoverflow and give me a vote up :D?

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: 2010-05-04 23:48:44 +0800

Seen: 670 times

Last updated: May 05 '10

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