Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
889 views
in Technique[技术] by (71.8m points)

jsf - 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.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)?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
<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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.6k users

...