# listbox iteration variable binding in macro component

circum
0

Hi all,

I am trying to create my first macro component, and don't understand why does not work the binding for itaration variable in a listbox just like in a simple .zul file.

I want to use it something like this:

<mymacrocomponent model="@load(vm.someModel)"/>


This is not working in mymacro.zul:

<zk apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('hu.engard.zk.MultiAutoCompleteTextbox')">
<template name="model" var="item">
</template>
</listbox>
[...]


OTOH, this works:

<zk apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('hu.engard.zk.MultiAutoCompleteTextbox')">
<template name="model">
<listitem label="${each.label}"></listitem> </template> </listbox> [...]  I implemented the macro's custom class as: @ComponentAnnotation("model:@ZKBIND(ACCESS=load)") public class MyMacroComponent extends HtmlMacroComponent { public void setModel(ListModel<? extends ITag> model) { ((Listbox)getFellow("mc_listbox_test")).setModel(model); } }  Can you explain me why the former (which is the typical syntax for MVVM .zul files) does not work? Actually, it seems that the whole binding -- i.e., the apply=BindComposer, the model="@load(arg.model)" in listbox and the @ComponentAnnotation is not necessary (can be removed), as it works by the setModel() method alone, but if I remove the setModel(), it does not work... What am I missing? Thanks, Circum delete retag edit ## 2 Answers Sort by » oldest newest most voted answered 2014-05-11 22:13:00 +0800 nmpallas 115 4 http://nmpallas.wordpress... The problem is clearly a typo mistake.This change should make the trip happen. @init or @load is a matter of taste but I prefer for grid and listboxes to use @init  <zk apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('hu.engard.zk.MultiAutoCompleteTextbox')"> <listbox id="mc_listbox_test" model="@init(vm.model)> <template name="model"> <listitem label="${each.label}"></listitem>
</template>
</listbox>


nmpallas
115 4
http://nmpallas.wordpress...

Also keep in your mind that you could use JavaEE6/7 fully @Named qualified beans and not having as @init('full.class.qualified.name') and let CDI do the resolving making your code less error prone to typos :).

hope it helps \n\m

[hide preview]