0

issue creating dynamic tabs via controller #2

asked 2013-05-06 14:42:17 +0800

bbrand gravatar image bbrand
98 3

updated 2013-05-07 09:32:27 +0800

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="&lt;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?

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2013-05-07 14:26:48 +0800

ryg78 gravatar image ryg78
29 2

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

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: 2013-05-06 14:42:17 +0800

Seen: 35 times

Last updated: May 07 '13

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