-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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>
I answered you here :).
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.
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?
Asked: 2010-05-04 23:48:44 +0800
Seen: 670 times
Last updated: May 05 '10