0

Loading different templates depending on the data from a tree model

asked 2017-08-09 14:56:19 +0800

ajamardo gravatar image ajamardo
21 3

I have this situation. I have a treemodel on the left part of the page with 3 levels. EquipmentClass, EquipmentType and Equipment. Each level has to load a different template, EquipmentClass.zul , EquipmentType.zul and Equipment.zul.

I've tried several stuff so far, but I always find any problem at some point. What's the best approach to do this?

This case doesn't work for me, because in the template, I'll do some save and load of Media fields, and that's not well handled in the zul, and I can't access the @ref p from viewmodel

<if test="@bind(not empty vmApp.type)"> <include id="dataForm" p="@ref(vmApp.selected)" src="@load(vmApp.templateName)" /> </if>

Next case doesn't work neither for me, because even I get the data in the template from the selectedId, if the selectedId changes, it doesn't get binded to the template, because the variable is 'sent' when the template gets constructed

<if test="@bind(not empty vmApp.type)"><include id="dataForm" selectedId="@load(vmApp.selectedId)" src="@load(vmApp.templateName)" /></if>

Note that:

@DependsOn({"type"})

public String getTemplateName() {

    return this.type == null ? "" : "/app/thg/equipments/equipments/"+ type +".zul";
}

I hope you can address me with this situation.

Disclaimer: I'm a really newbie in ZK

delete flag offensive retag edit

Comments

I am not really sure how to help efficiently with the given information. <include> might be a too complex component and can be replaced by <apply>. Also if you can provide a running example on https://zkfiddle.org it will be much clearer what's going wrong.

cor3000 ( 2017-08-10 03:10:26 +0800 )edit

some background on <apply> vs <include> https://www.zkoss.org/wiki/SmallTalks/2016/October/ZK8FeaturesforMVC-ShadowElements-Part1

cor3000 ( 2017-08-10 03:10:52 +0800 )edit

I've checked the apply, but what if I want to send to the template an object as a parameter and being able to access it in the VM of the template?

ajamardo ( 2017-08-10 07:26:51 +0800 )edit

that's some good information... I'll put something together... if not today, tomorrow ... please remind me if I forget it somehow. kind of busy today

cor3000 ( 2017-08-10 08:12:31 +0800 )edit

should be possible with init(@ExecutionParam("selected") SomeClass selectedObject) http://books.zkoss.org/zk-mvvm-book/8.0/syntax/executionparam.html and <apply src="bla.zul" selected="@load(vmApp.selected)"/> The template content will then automatically rerender when the selected item changes.

cor3000 ( 2017-08-10 08:17:46 +0800 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-08-10 10:42:35 +0800

cor3000 gravatar image cor3000
4366 2 7
ZK Team

I put together a small example showing how to pass a parameter into an innerVM via @ExecutionArgParam.

http://zkfiddle.org/sample/3s936ku/6-apply-with-execution-arg-param

For the apply parameter I am using @load instead of @ref to pass the parameter into the template.

<apply templateURI="inner.zul" locale="@load(outerVM.selectedLocale)"/>

instead of

<apply templateURI="inner.zul" locale="@ref(outerVM.selectedLocale)"/>

@load will trigger the template to reapply the content so that a new instance of InnerVM is created everytime the selectedLocale changes.

@ref will not reload the template and allow reusing the inner template components. However this will not initialize an new InnerVM so that the updated locale parameter never reached the InnerVM (which stays the same object).

Both cases have their usage... here I prefer destroy the old inner.zul and instantiate a new one. Avoids having to clean up.

Robert

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
2 followers

RSS

Stats

Asked: 2017-08-09 14:56:19 +0800

Seen: 17 times

Last updated: Aug 10 '17

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