-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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')">
<listbox id="mc_listbox_test" model="@load(arg.model)>
<template name="model" var="item">
<listitem label="@load(item.label)"></listitem>
</template>
</listbox>
[...]
OTOH, this works:
<zk apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('hu.engard.zk.MultiAutoCompleteTextbox')">
<listbox id="mc_listbox_test" model="@load(arg.model)>
<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
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>
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
Asked: 2014-05-11 21:04:42 +0800
Seen: 21 times
Last updated: May 11 '14
ZK drang and drop and databinding [closed]
Create Crud of a User that has a collection of books
Create a Zk session variable with a menu
Upload Button dosn't work on chrome
Getting selected ListBox values on button Click | ZK
Problem binding values to a composite component
How to access static member field of a class in zul without zscript