-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi i have a case, how do i add children from tab dinamically. i have example
my view
<include mode="instant" sclass=""
currentPage="@ref(vm.currentPage)" >
<tabbox model="@load(vm.tabsModel)" >
<template name="model:tab" var="subTitle">
<tab label="@load(currentPage.subTitle)">
</tab>
</template>
<template name="model:tabpanel" var="includeUri">
<tabpanel>
<include src="@load(currentPage.includeUri)"></include>
</tabpanel>
</template>
</tabbox>
</include>
then this java code
public class NavigationViewModel { NavigationPage currentPage; private Map<string, map<string,="" navigationpage="">> pageMap;
ListModelList<Tabbox> tabsModel = new ListModelList<Tabbox>();
{
}
@Init
public void init() {
initPageMap();
currentPage = pageMap.get("ZK's Pizza").get("About Us");
}
@Command
public void navigatePage(@BindingParam("target") NavigationPage targetPage) {
BindUtils.postNotifyChange(null, null, currentPage, "selected");
currentPage = targetPage;
BindUtils.postNotifyChange(null, null, this, "currentPage");
}
public NavigationPage getCurrentPage() {
return currentPage;
}
public Map<String, Map<String, NavigationPage>> getPageMap() {
return pageMap;
}
private void initPageMap() {
pageMap = new LinkedHashMap<String, Map<String, NavigationPage>>();
Tabbox newTabbox = new Tabbox();
Tabs newTab = new Tabs();
tabsModel.add(newTabbox);
newTabbox.appendChild(newTab);
newTabbox.getTabs();
newTabbox.getSelectedPanel();
addPage("ZK's Pizza", "About Us", "/home/about_us.zul");
addPage("ZK's Pizza", "Menu", "/home/menu.zul");
}
private void addPage(String title, String subTitle, String includeUri) {
addPage(title, subTitle, includeUri, null);
}
private void addPage(String title, String subTitle, String includeUri, String data) {
String folder = "/widgets/menu/navbar/pages";
Map<String, NavigationPage> subPageMap = pageMap.get(title);
if(subPageMap == null) {
subPageMap = new LinkedHashMap<String, NavigationPage>();
pageMap.put(title, subPageMap );
}
NavigationPage navigationPage = new NavigationPage(title, subTitle,
folder + includeUri + "?random=" + Math.random(), data) {
@Override
public boolean isSelected() {
return currentPage == this;
}
};
subPageMap.put(subTitle, navigationPage);
}
public ListModelList<Tabbox> getTabsModel() {
return tabsModel;
}
Thanks for any suggestions and ideas! Best Regards.
First of all: which version of zk are you using? template in tabbox is not present in CE version.
For this reason, I resolved it in this way (using MVC pattern).
<tabbox height="100%" id="tabbox">
<tabs />
<tabpanels />
</tabbox>
And in vm:
@Wire Tabbox tabbox = new Tabbox();
...
@Listen("onClick = myButton")
public void addTab() {
Tab t = new Tab("nameOfTab");
t.setSelected(true);
t.setClosable(true);
t.setParent(tabbox.getTabs());
Tabpanel tp = new Tabpanel();
tp.appendChild(new Include("urlToViewInTab.zul"));
tp.setParent(tabbox.getTabpanels());
tabbox.getTabpanels().appendChild(tp);
}
anyway the dependent ZK version 'barracus' has showed good code for doing this. For adding your pages you must add TWO components to your Tabbox.
Asked: 2017-02-28 04:25:10 +0800
Seen: 68 times
Last updated: Mar 06 '17
How to control selectAll() feature in a Listbox with multiple=true and checkmark=true
ZK8 Wizard Series: Part 2 now released!
Faster And Lighter, The Performance Test On ZK8
org.zkoss.xel.XelException: Resource not found: http://www.zkoss.org/dsp/web/core
How To Check Dirty Status in ZK8?
Come and join the ''JS'' Hunt!