1

Children Binding : UiException Callable only in the event listener

asked 2013-11-02 21:33:03 +0800

samroy gravatar image samroy
25 2

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.

delete flag offensive retag edit

5 Replies

Sort by » oldest newest

answered 2013-11-04 01:27:58 +0800

dennis gravatar image dennis
3679 1 6
http://www.javaworld.com....

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.

link publish delete flag offensive edit

answered 2013-11-04 13:39:36 +0800

samroy gravatar image samroy
25 2

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;
        }

}
link publish delete flag offensive edit

answered 2013-11-13 09:42:28 +0800

keyevent gravatar image keyevent
2 2

having same problem. I guess the only way out is to create children in composer, which is not elegant by my personal view

link publish delete flag offensive edit

answered 2014-02-05 10:21:38 +0800

cor3000 gravatar image cor3000
6280 2 7

updated 2014-02-06 05:49:22 +0800

maybe a less invasive workaround:

<div fulfill="self.onCreate"> <!-- workaround -->
  <vlayout children="@load(vm.listStrings)">
</div>

Robert

link publish delete flag offensive edit

answered 2014-03-02 00:35:10 +0800

samroy gravatar image samroy
25 2

Excellent. I really prefer your fulfill strategy with "self.onCreate". Thank you very much.

Sam.

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

RSS

Stats

Asked: 2013-11-02 21:33:03 +0800

Seen: 64 times

Last updated: Mar 02 '14

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