0

how to create add tab dinamically

asked 2017-02-28 04:25:10 +0800

bayuprams gravatar image bayuprams
1

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.

delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest

answered 2017-02-28 11:09:17 +0800

barracus gravatar image barracus flag of Italy
38 4

updated 2017-02-28 11:18:38 +0800

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);

}
link publish delete flag offensive edit

answered 2017-03-02 04:43:59 +0800

bayuprams gravatar image bayuprams
1

thank'u for your reply yup i know, i using zk 8.0.4.1 EE. if i want to continue my code, do you have solution?

link publish delete flag offensive edit

answered 2017-03-02 14:44:23 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

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.

  1. Tab
  2. Tabpanel
link publish delete flag offensive edit

answered 2017-03-06 03:25:30 +0800

bayuprams gravatar image bayuprams
1

problem solved, thanks all.

link publish delete flag offensive edit
Your reply
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
1 follower

RSS

Stats

Asked: 2017-02-28 04:25:10 +0800

Seen: 68 times

Last updated: Mar 06 '17

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