0

Apply BindComposer without creating a window

asked 2012-02-25 21:27:40 +0800

ctapobep gravatar image ctapobep
163 2

I have a menu and a main working area. When someone clicks on the menu, I create a window from ZUL file and place it into the main area. But along to that I cache this component:

 Map<String, Component> mainAreaWindowsCache
Next time someone clicks the same menu item, I don't create the component again, but rather retrieve it from cache and setParent(mainWorkingArea). But it appeared that it has different effect - the BindComposer doesn't apply in such case and the ViewModel of the super-main window (with both menu and main working area) is used in @commands.
Question is how can I say to that cached window to re-apply the BindComposer and reload data from VM?

delete flag offensive retag edit

6 Replies

Sort by ยป oldest newest

answered 2012-02-25 23:28:22 +0800

Matze2 gravatar image Matze2
773 7

I guess the composer is still applied. For the reload, you can try with

binder.notifyChange(this, "*");

The binder is available in the BindContext.

link publish delete flag offensive edit

answered 2012-02-26 06:07:04 +0800

ctapobep gravatar image ctapobep
163 2

updated 2012-02-26 06:11:28 +0800

Thanks for the reply. This doesn't help though :) What you suggested is to trigger all @NotifyChange in the this VM, right? Let me give you more details: the problem itself is that I have 2 VMs. One is the VM of the WholeArea that listens to the menu pressing, and the VM of the working area. When I attach the WorkingArea component back to the WholeArea, it doesn't recognizes that there is this WorkingAreaVm, it only sees WholeAreaVm and tries to trigger @commands on it.
This schema works if instead of caching the WorkingArea components I create them from scratch every time, but I'd like to cache them..
PS: if it's possible, could you point out what is the object graph/relationships and the lifecicle in scope of Bindings and ViewModels.

link publish delete flag offensive edit

answered 2012-02-26 07:25:12 +0800

benbai gravatar image benbai
2228 6
http://www.zkoss.org

Hi ctapobep,

Do you mean you have a WorkingAreaVm inside a WholeAreaVm ?
Currently I will suggest you provide a 'getter' in WholeAreaVm ,
and use command in WholeAreaVm to trigger the real method in WorkingAreaVm .

In zul page, there is something like '@command('doSomethingOfWorkingArea')' that trigger the method in WholeAreaVm ,
in WholeAreaVm, has a method and a getter below:

@NotifyChange('workingVM')
public void doSomethingOfWorkingArea () {
    workingAreaVM.doSomething();
}
public WorkingAreaVM getWorkingVM () {
    if (WorkingAreaVM == null)
        initWorkingVm();
    return WorkingAreaVM;
}

i.e., everything handled by the WholeAreaVm,
and trigger the method of WorkingAreaVM or update WorkingAreaVM by it.

Regards,
ben

link publish delete flag offensive edit

answered 2012-02-26 07:31:42 +0800

ctapobep gravatar image ctapobep
163 2

Well, this version would clutter the main VM, thus I made it differently :) The WholeArea is a window and it has a viewModel defined that gets the VM from Spring context. The WorkingArea is also a window inside WholeAreaWindow and it also has viewModel which it can also acquire from Spring Context. Thus these two VMs are totally decoupled, they don't know about each other. The WholeAreaVm just creates a window which grabs its VM on its own.

link publish delete flag offensive edit

answered 2012-12-19 17:12:03 +0800

cyiannoulis gravatar image cyiannoulis
1201 10

I am facing now the same problem.

Anyone?

/costas

link publish delete flag offensive edit

answered 2013-01-08 09:26:13 +0800

benbai gravatar image benbai
2228 6
http://www.zkoss.org

Hi,

You can try MVVM in java?

Regards,
Ben

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: 2012-02-25 21:27:40 +0800

Seen: 214 times

Last updated: Jan 08 '13

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