Is there a way to create dynamically <rich:tab> elements?

纵饮孤独 提交于 2019-11-30 09:02:41

问题


Let say that I want to create a variable set of <rich:tab> elements within a <rich:tabPanel> component. So I tried to do that way:

<rich:tabPanel switchType="client" ...>
    <ui:repeat value="#{myBean.myTabs}" var="tab">
        <rich:tab name="#{tab.name}" label="#{tab.label}"/>
    </ui:repeat>
</rich:tabPanel>

But it didn't work, as no tab is rendered. I also got the following message in the logs:

j_id174: tab panel has no enabled or rendered tabs!

This problem seems to be encountered by others people, for example here.

So as suggested by the previous thread, I replaced my <ui:repeat> by a <c:forEach> but the problem still occurs.


I have a way to solve this problem using the binding attribute of my <rich:tabPanel> component:

<rich:tabPanel switchType="client" binding="#{tabNavigationBean.tabPanel}"
</rich:tabPanel>

and then in my Java bean:

private HtmlTabPanel tabPanel; // + getter and setter

public void setTabPanel(HtmlTabPanel tabPanel) {
    this.tabPanel = tabPanel;
    if (tabPanel != null) {
        createTabs();
    }
}

private void createTabs() {
    Application application = FacesContext.getCurrentInstance().getApplication();
    HtmlTab newTab = null;
    for (DedicatedPageTab dpt : getDedicatedPageTabs()) {
        newTab = (HtmlTab) application.createComponent(HtmlTab.COMPONENT_TYPE);
        newTab.setLabel(dpt.getLabel());
        newTab.setName(dpt.getName());
        tabPanel.getChildren().add(newTab);
    }
}

This code is working.

However, my question is to know if I can solve my problem without using the binding attribute (i.e. a 100% pure XHTML solution)?


回答1:


<a4j:outputPanel id="out">
    <rich:tabPanel>
        <c:forEach items="list" var="var">
            <rich:tab label="#{var.name}" switchType="client">
                content
            </rich:tab>
        </c:forEach>
    </rich:tabPanel>
</a4j:outputPanel>



回答2:


Yes, it is possible, but difficult. Here are some notes I have:

Use c:forEach to create tab tags inside tabPanel inside outputPanel. reRender outputPanel on tab removal, add, or name change

http://relation.to/11633.lace

http://devharbor.blogspot.com/2009/08/add-jsf-controls-dynamically-with.html


We also made use of templating, though I still have an outstanding issue for it: How to force the build phase in a JSF 1.2 page using JSTL?

http://facelets.java.net/nonav/docs/dev/docbook.html#template Docs on templating

http://www.jsfcentral.com/articles/facelets_3.html Templating tutorial



来源:https://stackoverflow.com/questions/4022193/is-there-a-way-to-create-dynamically-richtab-elements

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!