Thanks, @cor3000, I'll look the link you've sent me. It seems a better choice putting in include
this data
property.
-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi,
I have a NavigationViewModel
which is responsible for redirect and show the content of my application, and that is my include:
<div class="container is-fluid" style="padding-top: 3.25rem;">
<div class="columns">
<include self="@define(content)" viewModel="@id('vm') @init('NavigationViewModel')" src="@load(vm.content)" />
</div>
</div>
And this is the navigation method:
@GlobalCommand
@NotifyChange("content")
public void goTo(@BindingParam("content") String content) {
if (content != null) this.content = content;
}
So, going to Person page would be something like
@global-command('goTo', content='/person/index.zul')
Since I have index.zul
and form.zul
, and different ViewModel for each one of them, is it possible to create a method or include a parameter to pass the id
of selected person from index.zul
to form.zul
? I've tried by using @BindingParam("id")
in goTo
method, but it didn't work. I need to pass a param from a viewmodel to another one.
I hope this runnable example explains how this can be done: http://zkfiddle.org/sample/3971936/4-Global-Command-Navigation-with-Params
The non obvious part is the "specialty" about <include>
that it is only reloading when the url changes ... you might start a fake url parameter but I'd recommend against is, since <include>
behaves differently when using url parameters - just to change the src (defer mode has all sorts of side effects you don't want to be worried about). So it's clearer to simply reset the src to null
for an instant and force a re-render of the include like that.
Parameters passed into an <include>
can be accessed with the @ExecutionArgParam
annotation.
IMPORTANT: the order of parameters in the zul and when calling postNotifyChange matters.
<include>
needs to receive the data
before changing the src
-attribute (or it will re-render with the previous value)
<include data="@load(navVM.data)" src="@load(navVM.page)"/>
BindUtils.postNotifyChange(null, null, this, "data");
BindUtils.postNotifyChange(null, null, this, "page");
I suggest sticking to a single "data" parameter which can be any java object and hence contain arbitrarily complex navigation information.
ZK-EE users should use the <apply>
-shadow-element which doesn't require the forceReload approach e.g.:
<apply templateURI="@load(navVM.page)" data="@load(navVM.data)"/>
With <apply>
the parameter order doesn't matter.
Thanks, @cor3000, I'll look the link you've sent me. It seems a better choice putting in include
this data
property.
I don't know if it's the better choice, but in my FormViewModel
there is a @BindingParam("id")
which binds the id selected in list.zul
.
I did this on form.zul
:
<div class="section" viewModel="@id('vm') @init('PersonFormViewModel', id = navigation.id)">
</div>
It works for static values, now I'll try with real objects.
Asked: 2018-03-09 21:46:59 +0800
Seen: 54 times
Last updated: Mar 13 '18
How to bind a Model with a Viewmodel
search button using validation
my login/index zul page is loading twice, where as i am only calling it once
Databinding and auto-complete on combobox
Multiple selection using ListModelMap<Key, Obj>
Editable interface to add users
Upload csv files with Zk framework