0

zk 6 zkbinding notification issues

asked 2011-11-20 05:35:00 +0800

GGW gravatar image GGW
84 1

updated 2011-11-20 06:09:17 +0800

I'm converting an existing project to zk6 and like the new zkbinding except one problem. I have two separate pages (on the same desktop), each having a Zul and VM and each having a listbox. Changing the selection of the listbox on the first page should send a new set of data to be shown in the listbox on the second page. The listbox on the second page binds to the vm.items:
ZUL (second page)

            <listbox 
                     multiple="true" height="200px" fixedLayout="true" 
		     model="@bind(vm.items)" selectedItem="@bind(vm.selected)" >
            <listhead>

The vm has the following method to update the items for the listbox:

VM (second page)

    @NotifyChange({"selected","items"})
    public void setItems(List newItems) {
        
        this.items=new ListModelList (newItems);
        this.selected=null;
    }

This method is to be called by the VM of the first page when a new selection is made on its listbox. The method does its job in terms of updating the mv.items, but notification doesn't not seem to work because the second listbox does not show changes even if the corresponding vm.items has changed as a result of the above method being called.

I verified that the above code works fine if called by a button event of the second page itself, for example:
ZUL (seond page):

 <button  label="Update" onClick="@bind('updateBtn')" />

VM (second page):

        @NotifyChange({"selected","items"})
	public void updateBtn(){
               ArrayList newList = getUdatedList();
               setItems(newList);           
	}
	


I'm not sure whether this is a bug. Please help. Thanks.

delete flag offensive retag edit

7 Replies

Sort by ยป oldest newest

answered 2011-11-20 06:19:03 +0800

GGW gravatar image GGW
84 1

As a way to get around it, does anyone know whether it is possible in zk 6 to get the binder of the second page so that I can call binder.loadAll() manually from the first page as I did in zk5? Thanks.

link publish delete flag offensive edit

answered 2011-11-20 11:31:26 +0800

GGW gravatar image GGW
84 1

Is there anyway to get a reference to the BindComposer instance so that I can try to call its notifyChange() method? Right now, it seems the only way to communicate from VM to view is via the java @NotifyChange notation (which works great between the view and its associated VM). However, when it fails to work, like in my case where backend changes is initiated from a different VM and the java notification notation doesn't seem to work , there is nothing left that we can use to update the view from a different VM (there is no problem to change the VM's property from a different VM). Any comments?

link publish delete flag offensive edit

answered 2011-11-20 13:46:40 +0800

GGW gravatar image GGW
84 1

OK, just before giving up and going back to 5.09. I got it work now after digging into the source. The java notation way is much more elegant but it just does work in inter VM communication. I think it is a bug that causes it doesn't work as it supposed to be. What I did is:

1. Create a new bindcomposer extending the stock BindComposer

2. Add to it a new method for refreshing all bindings:

       public void loadthem(){
       myBinder.loadComponent(comp);    
    }

where myBinder and comp is obtained from the base BindComposer by overriding doAfterCompose()

    private AnnotateBinderImpl myBinder;
    private Component comp;
@Override
        public void doAfterCompose(Component comp) throws Exception {
            super.doAfterCompose(comp);
               
            myBinder=(AnnotateBinderImpl)this.getBinder();
            
            this.comp=comp;
        }
 

3 From the first VM, update the second VM's binding properties first and then call loadthem() of the customary bindComposer instance associated with the second VM. I used a session Map to hold all the vms and customary bindComposers so that they can be call from anywhere in the program.

This is not an elegant solution (similar to what I used in zk5) and but I will enable me to use zk6 without going back to zk5. I hope the zkbind java annotation mechanism of zk 6 will work with inter vm communication some later days.

link publish delete flag offensive edit

answered 2012-03-15 09:00:48 +0800

fredrikoe2 gravatar image fredrikoe2
60

Hi.

I have the same problem with ZK 6.0.1-FL-2012-03-05. I don't get binding to work when using several view models which is usually the case in a real world application.

Consider this simple example with listing and editing info about persons:
1) A list of persons full names to the left
2) Clicking on one persons name opens a form to the right
3) Change the persons surname and press save
4) The full name should be updated in the list

Please note that the name in the list should only be updated when the user has pressed save, not automatically when leaving the form for editing the surname.

What is the best practice of doing this with ZK 6 MVVM? All the examples I've found contains only one page and one view model and in this trivial case it works as expected but as soon as I try to communicate between view models and pages, the binding breaks just as GGW explains above.

Thanks in advance.
/ Fredrik

link publish delete flag offensive edit

answered 2012-06-26 09:48:58 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8
http://emrpms.blogspot.in...

Hi Fredrikoe2

You can see my example here

link publish delete flag offensive edit

answered 2012-06-26 19:54:11 +0800

pasqualeleone gravatar image pasqualeleone flag of Italy
81 2

Hi,
thank you for this article.
I have a question (for part3):
you used a MVVM pattern to develop application, is right to use @Wire binding of complex Object as Button or window?
I think that is very convenient and easy to manage the buttons from java code.
Also I am developing an application following MVVM but I do not know what strategy to use to bind complex objects in Java code.
The approach @ Wire, as well as the @ BindingParam is not recommended because compromises the decoupling between view and model, characteristic of the MVVM. Do you think it is right to use it?
What would be the alternative to have a pure MVVM pattern?

link publish delete flag offensive edit

answered 2012-06-27 01:09:12 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8
http://emrpms.blogspot.in...

Hi

Actually When i started learning ZK, i was very impressed about MVVM pattern, because of its loose coupling. So started developing small examples based on MVVM.
First issue came when i try to close the model window in MVVM. After searching the forum, i found that there is no solution for that, all are recommending to wire components using select composer.

So i also started following the same thing even though i am compromising MVVM. And also, regarding Button, in my example, i made read only depending on some condition. This can be done in the ZUL File intself and make PURE mvvm , but since i already wired for some other reason, so i continued do all the other actions
in the same way.

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

RSS

Stats

Asked: 2011-11-20 05:35:00 +0800

Seen: 437 times

Last updated: Jun 27 '12

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