How to dynamically link zul page with viewmodel at runtime

asked 2015-05-07 14:40:13 +0800

ivtu gravatar image ivtu
11 2

updated 2015-05-08 08:19:51 +0800

Hello, what is the best way to dynamically link zul page with viewmodel? My project is modularized (mvvm pattern). module1 'sees' module2, but module1 is optional. module1's viewmodel extends module2's viewmodule. I want to link zul page with viewmodel based on what module is installed/deployed. If module1 is installed, viewmodel from module1 should be used and if it is not, viewmodel from module2 should be used. I did this via page attribute but this is not the best way.

UPDATE: zul page is inside module2 and module2 does not 'see' module1. Based on this I cannot use 'abstract viewmodel' with getter to the 'real' viewmodel.

Thank you in advance.

delete flag offensive retag edit

3 Answers

Sort by ยป oldest newest most voted

answered 2015-05-08 06:22:01 +0800

kishor11 gravatar image kishor11

Add the Binding @DependOn it. i am not much aware about it so to use this.

link publish delete flag offensive edit

answered 2015-05-08 06:33:18 +0800

chillworld gravatar image chillworld flag of Belgium
5357 4 9

You have multiple solutions.

One solution I use in a project is an second viewmodel who has a getter for the "real" viewmodel.

example :

<div self="@{define(body)}" apply="org.zkoss.bind.BindComposer" viewModel="@id('abstractvm') @init('be.mil.web.vm.catalog.AbstractCommonVM')">
    <div apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init(abstractvm.vmClass)">
link publish delete flag offensive edit

answered 2019-07-25 15:02:06 +0800

Matthias84 gravatar image Matthias84
3 2

updated 2019-07-25 15:15:59 +0800

Does your getter for the "real" viewmodel return its name as a String or the actual viewmodel class?

Also: in your inner div, how do you tell zk to use the real viewmodel to look for commands, etc. and not the abstract one?

link publish delete flag offensive edit


I think this is a very old question ... are you trying to help, or do you have a similar issue and need help?

cor3000 ( 2019-07-26 11:40:41 +0800 )edit

I was indeed having a similar issue. But I have found a way around it using some sort of Delegation mechanism. Thanks anyway. :)

Matthias84 ( 2019-07-26 17:47:06 +0800 )edit

Second question is with the ID's you set dor each viewmodel. You have abstractvm and vm. Commands always goes to the nearest VM, so they Will ben triggered to vm and not abstractvm. First question, i think i returned string with the fqn, bit not sure about that. Can't look in that project anymore.

chillworld ( 2019-07-27 12:28:02 +0800 )edit
Your answer
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




Asked: 2015-05-07 14:40:13 +0800

Seen: 36 times

Last updated: Jul 25 '19

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