-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I am working on a project that requires me to add multiple TAB's dynamically, and each TAB has in turn a number of tabs. I have hit a couple of issues:
ZUL:
<?xml version="1.0" encoding="UTF-8"?>
<zk xmlns="<a href=" http:="" www.zkoss.org="" 2005="" zul"="">http://www.zkoss.org/2005/zul"> <window id="mainWindow" width="100%" height="100%" apply="controller.test">
<borderlayout>
<!-- header frame -->
<north title="Dynamic Tabs" vflex="true">
<grid id="headerFrame" fixedLayout="true" width="100%" height="100%" >
<columns>
<column label="" width="50px"/>
<column label=""/>
</columns>
<rows>
<row>
<label value="Add tab"/>
<button id="addButton"/>
</row>
</rows>
</grid>
</north>
<!-- map frame -->
<south id="planFrame" size="90%" vflex="true">
<tabbox id="tabHolder">
<tabs/>
</tabbox>
</south>
</borderlayout>
</window>
</zk>
and the controller:
package controller;
import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.util.Composer; import org.zkoss.zk.ui.util.GenericForwardComposer; import org.zkoss.zul.Button; import org.zkoss.zul.South; import org.zkoss.zul.Tab; import org.zkoss.zul.Tabbox; import org.zkoss.zul.Tabpanel; import org.zkoss.zul.Toolbar; import org.zkoss.zul.Toolbarbutton; import org.zkoss.zul.Window; // public class test extends GenericForwardComposer implements Composer {
Window mainWindow;
Button addButton;
South planFrame;
Tabbox tabHolder;
int i = 0;
@Override
public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
addButton.setDisabled(false);
}
public void onClick$addButton(Event event) {
//
Tab rmTab = new Tab("a new tab " + ++i);
rmTab.setParent(tabHolder.getTabs());
//
Tabpanel rmTabpanel = new Tabpanel();
rmTabpanel.setParent(tabHolder.getTabpanels());
rmTab.setSelected(true);
}
}
This works, but ONLY if you include the "empty" TABS component. Remove this and it does not work, which in my view is incorrect. The line rmTab.setParent(tabHolder.getTabs()); should take care of this regardless?
Hi,
if you remove the "empty" TABS, I guess you got NullPointerException in line tabHolder.getTabs(); Because in ZUL there's no such Tabs has been declared. So it won't be parsed and automatically initialized.
If you don't want to put the "empty" TABS, you can try to initialize the component Tabs by yourself. Tabs tabs = new Tabs(); tabs.setParent(tabHolder); // attach it to your tabHolder rmTab.setParent(tabHolder.getTabs());
I hope that works.
Regards, Henry Girsang
Asked: 2013-05-06 14:42:17 +0800
Seen: 35 times
Last updated: May 07 '13
How to Get ViewModel From a Tab class? [closed]
issue creating dynamic tabs via controller #1
enhancement needed in scrolling tab in tabbox using javacode
Tabbox with Toolbar: how do I give the Toolbar all available space?
Tabbox and Notifications issue
Issue in Tab close event enhancement
Attach existing ViewModel to new tab