0

listbox iteration variable binding in macro component

asked 2014-05-11 21:04:42 +0800

circum gravatar image 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')">
<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

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2014-05-11 22:13:00 +0800

nmpallas gravatar image 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>
link publish delete flag offensive edit
0

answered 2014-05-11 22:14:42 +0800

nmpallas gravatar image 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

link publish delete flag offensive edit
Your answer
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
2 followers

RSS

Stats

Asked: 2014-05-11 21:04:42 +0800

Seen: 21 times

Last updated: May 11 '14

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