开发者

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

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.getC开发者_Python百科urrentInstance().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)?


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜