Revision history [back]

click to hide/show revision 1
initial version

asked 2013-05-06 14:57:32 +0800

bbrand gravatar image bbrand

issue creating dynamic tabs in controller

I am trying to create tabs dynamically and am running into issues. The container TAB is created but the contents of that TAB is empty, while it should contain another TAB.

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>

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.Label; import org.zkoss.zul.South; import org.zkoss.zul.Tab; import org.zkoss.zul.Tabbox; import org.zkoss.zul.Tabpanel; 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);
    //
    // now add a tabbox to that tab
    Tabbox rmBox = new Tabbox();
    rmTabpanel.appendChild(rmBox);
    // and a tab
    Tab yearTab = new Tab("Year");
    yearTab.setParent(rmBox.getTabs());
    Tabpanel yearTabpanel = new Tabpanel();
    yearTabpanel.appendChild(new Label("tab year 1"));
    yearTabpanel.setParent(rmBox.getTabpanels());
    yearTab.setSelected(true);

}

}

I have been over this code a lot of times and cannot find my error. Anybody?

thanks

issue creating dynamic tabs in controllervia controller #1

I am trying to create tabs dynamically and am running into issues. The container TAB is created but the contents of that TAB is empty, while it should contain another TAB.

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>

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.Label; import org.zkoss.zul.South; import org.zkoss.zul.Tab; import org.zkoss.zul.Tabbox; import org.zkoss.zul.Tabpanel; 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);
    //
    // now add a tabbox to that tab
    Tabbox rmBox = new Tabbox();
    rmTabpanel.appendChild(rmBox);
    // and a tab
    Tab yearTab = new Tab("Year");
    yearTab.setParent(rmBox.getTabs());
    Tabpanel yearTabpanel = new Tabpanel();
    yearTabpanel.appendChild(new Label("tab year 1"));
    yearTabpanel.setParent(rmBox.getTabpanels());
    yearTab.setSelected(true);

}

}

I have been over this code a lot of times and cannot find my error. Anybody?

thanks

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