-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi all !
I'm try to use MVVM with children and template.
Here is my Zul :
<zk>
<window apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('toto.VMToto')">
<vlayout children="@load(vm.listStrings)">
<template name="children" var="myString">
<label value="@bind(myString)"/>
</template>
</vlayout>
</window>
</zk>
and now my ViewModel :
public class VMToto
{
List<String> listStrings = new ArrayList<String>();
@Init
public void init()
{
listStrings.add("Alpha");
listStrings.add("Bêta");
listStrings.add("Gamma");
}
public List<String> getListStrings()
{
return listStrings;
}
public void setListStrings(List<String> listStrings)
{
this.listStrings = listStrings;
}
}
With this code, I get this error :
org.zkoss.zk.ui.UiException: Callable only in the event listener
at org.zkoss.zk.ui.event.Events.sendEvent(Events.java:334)
at org.zkoss.zk.ui.event.Events.sendEvent(Events.java:348)
[...]
But, if I do not add Strings to my list in the init method, everything goes fine. What do I miss here ?
Thank you :)
Sam.
I can run your example in zk fiddle with 6.5.3, http://zkfiddle.org/sample/36jsq04/1-Another-new-ZK-fiddle. You must be have some other errors, check if you mix different zk version jar files in to same project.
Hi Dennis, Thanks a lot for your answer.
I started a project from scratch and it did work, until I add this to zk.xml
<disable-event-thread>false</disable-event-thread>
So, I think it is a kind of a bug in ZK. This should work even with this option, I suppose.
I wonder if I should go further with the Zk Team to warn them about this issue.
The only other way I was able to make it work, and it is not elegant at all, was adding a handler to onCreate and adding a new method (init2) to my view model.
init2() will prepare the object and send a notify change.
Sam.
toto.zul
<zk>
<window apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('toto.VMToto')">
<attribute name="onCreate">
vm.init2();
</attribute>
<vlayout children="@load(vm.listStrings)">
<template name="children" var="myString">
<label value="@bind(myString)"/>
</template>
</vlayout>
</window>
</zk>
VMToto.java
public class VMToto
{
List<String> listStrings = new ArrayList<String>();
@Init
public void init()
{
}
public void init2()
{
listStrings.add("Alpha");
listStrings.add("Bêta");
listStrings.add("Gamma");
BindUtils.postNotifyChange(null, null, this, "*");
}
public List<String> getListStrings()
{
return listStrings;
}
public void setListStrings(List<String> listStrings)
{
this.listStrings = listStrings;
}
}
maybe a less invasive workaround:
<div fulfill="self.onCreate"> <!-- workaround -->
<vlayout children="@load(vm.listStrings)">
</div>
Robert
Asked: 2013-11-02 21:33:03 +0800
Seen: 63 times
Last updated: Mar 02 '14
MVVM Validator: class not found ? [closed]
Conditional evaluation component in mvvm
Attributes in macro was not updated after notifyChange
Problem binding values to a composite component
How to access static member field of a class in zul without zscript
How can i load a constant in .zul
MVVM tab box - delay @load until tab pane displayed?
mvvm, load or save with after or before for seach command
how to fire an event when a variable value loaded through VM