-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi i have problem, i did created include src on navbar and thats work. But the problem how to set include src dynamically.
here my sidebar.zul
<div id="sidebar" sclass="sidebar" apply="com.demo.controller.SidebarComposer" >
<div viewModel="@id('vm') @init('com.metrasys.controller.NavigationViewModel')">
<navbar id="navbar" sclass="nav-list" orient="vertical" collapsed="false"
onSelect="@command('navigatePage', target=self.selectedItem.attributes['navigationPage'])">
<nav label="DASHBOARD" iconSclass="z-icon-archive"
children="@load(vm.pageMap[self.label].values()) @template('navitem')"/>
<nav label="ADMIN" iconSclass="z-icon-user-secret"
children="@load(vm.pageMap[self.label].values()) @template('navitem')"/>
<template name="navitem" var="navigationPage">
<navitem label="@load(navigationPage.subTitle)" selected="@load(navigationPage.selected)"/>
</template>
</navbar>
</div>
</div>
and this my index.zul
<vlayout xmlns:n="native">
<div id="container" sclass="vertical"
viewModel="@id('vm') @init('com.demo.controller.NavigationViewModel')">
<include id="contentInclude" mode="instant"
currentPage="@ref(vm.currentPage)" >
<tabbox model="@bind(vm.tabsModel)" >
<template name="model:tabpanel">
<tabpanel>
<include src="@bind(currentPage.includeUri)">
</include>
</tabpanel>
</template>
</tabbox>
</include>
</div>
</vlayout>
and here my mainpage.zul
<zk xmlns:n="native">
<style src="/bootstrap/css/bootstrap.css"/>
<style src="/css/fonts.css"/>
<style src="/less/index.css.dsp"/>
<hlayout spacing="0">
<include src="sidebar.zul"/>
<vlayout spacing="0" hflex="1">
<include src="index.zul"/>
</vlayout>
</hlayout>
<script src="js/jquery.flot.pie.js"/>
<script src="js/jquery.sparkline.min.js"/>
</zk>
the problem is how to set include src dynamically from other page.
In MVVM where each VM represents the state of a part of the page you try to avoid changing the state of another VM directly. A simple way is to bind/post a global command when navigation occurs and listen to it in your NavigationViewModel.
At the bottom it explains how to trigger the command also dynamically from anywhere in your code.
Here the source code from our example: https://github.com/zkoss/zkessentials/blob/master/src/main/java/org/zkoss/essentials/chapter7/ajaxbased/mvvm/NavigationViewModel.java#L13
The VM listens to a @GlobalCommand "onNavigate" in order to update the src. In our example it is fired when a bookmark changes, but you can post a global command under any condition you need. example of dynamically posted global command
Asked: 2017-03-06 03:40:26 +0800
Seen: 56 times
Last updated: Mar 08 '17
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>
Notify Form of property change
How to handle lists and complex types with form?
multiple checkboxes in a row of listbox