zk viewmodel or selectorcomposer

818 views Asked by At

im newbie in zk´s world, so i have a doubt... i read already zk 8 documentation (almost all). At the office some partners are using ViewModel but inside some components are using Composer (selectorComposer) to bind some elements like this:

<div apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('com.some.package.SomeViewModel')">
<vbox>
... SOME ANOTHER ELEMENTS ....
<div apply="com.some.package.SomeComposer">
<hbox>
<vbox>
    <checkbox  ... more code...
    </checkbox>
</vbox>
</hbox>
</div>
</vbox>
</div>

i read that if you apply SelectorComposer you lost coupling... so what is the reason of taking SelectComposer within a ViewModel? or how it works?

Thanks a lot for any help.

1

There are 1 answers

2
dgofactory On BEST ANSWER

From my point of view SelectComposer allow you to reuse java code in a very traditional way. For example you can defined an AbstractController with functionality that will be reused in other controls of the same type with an slightly different functionality and extend the AbstractController. In this approach you can control the lifecycle of the componente by implemented the methods of SelectComposer like doAfterCompose. But actually you can do the same thing with pure MVVM, but instead of implement methods of SelectComposer you should use the annotations like @AfterCompose or @Init and you can extend the base class as well, to use your view you just have to change the tag in the zul file with something like:

<include src="/artifacts/componente_to_reuse.zul"/>

I think is just a matter of preferences, I preferred (and I always recommend) to use pure MVVM since it was available, and I haven't found any functionality that I couldn't reuse with MVVM approach.

References: Include, Zk annotations