有没有一种方法可以动态创建< rich:tab>元素? [英] Is there a way to create dynamically <rich:tab> elements?

查看:79
本文介绍了有没有一种方法可以动态创建< rich:tab>元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我说我想在<rich:tabPanel>组件内创建一个变量集<rich:tab>元素.所以我尝试这样做:

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.

因此,如前一个线程所建议,我将<ui:repeat>替换为<c:forEach>,但问题仍然存在.

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

我有一种方法可以使用我的<rich:tabPanel>组件的binding属性来解决此问题:

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>

,然后在我的Java bean中:

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

此代码有效.

但是,我的问题是想知道是否可以使用binding属性(即100%纯XHTML解决方案)不用解决我的问题?

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>

这篇关于有没有一种方法可以动态创建&lt; rich:tab&gt;元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆