0

Use ViewModel in Composite Component

asked 2015-05-22 05:10:07 +0800

JustinFrost gravatar image JustinFrost
145 1 6

I have defined a composite component that uses the following zul:

<div id="backpackWrap" apply="org.zkoss.bind.BindComposer" viewModel="@id('bvm') @init('foo.bar.CompView')">
      <Component/>
      <Component/>
</div>

When I use the composite component on the page, I get the following error:

org.zkoss.zk.ui.UiException: can't find Page to resolve a view model class :'foo.bar.CompView'

Is it possible to use a ViewModel inside the zul of a composite component ? If so how do I get this to work ?

Thanks,

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-05-27 07:44:24 +0800

JustinFrost gravatar image JustinFrost
145 1 6

Hi All,

I found a workaround for this, the composite component requires two zul files... Create an additional zull file for the composite component that is an include component with no src:

<include id="contentInclude"/>

In the composite component Java afterCompose method set the src of the include the the url of the zul that contains the view model and wire components again. Since the component is attached to a page before the include src is set everything works fine.

afterCompose(){
  contentInclude.setSrc("path/to/zul/with/viewmodel.zul");
  Selectors.wireVariables(this, this, null);
  Selectors.wireComponents(this, this, false);
  Selectors.wireEventListeners(this, this);

}
link publish delete flag offensive 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

Follow
1 follower

RSS

Stats

Asked: 2015-05-22 05:10:07 +0800

Seen: 33 times

Last updated: May 27 '15

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