【问题标题】:JSF - rich:tabPanel - A backing bean property is called for each tab and not for the active one onlyJSF - rich:tabPanel - 为每个选项卡调用支持 bean 属性,而不是仅针对活动选项卡
【发布时间】:2017-03-14 17:30:45
【问题描述】:

我有 15 个标签 包含一个类似的表格,所以我只有 一个支持 bean 的项目集合来定义我的表格。当标签更改时,集合相应地更改。所以,当标签被渲染时,我希望我的集合的 get 方法只被调用一次,对于我的活动标签,因为在屏幕和 DOM 中,这个标签是唯一一个有表格的标签.但是,我收藏的 get 方法被调用了 15 次,我猜这是因为我有 15 个标签。

你是怎么解释的?这是我的代码。

<rich:tabPanel activeItem="#{myBean.selectedTab}" itemChangeListener="#{myBean.changeItems}" >

    <c:forEach items="#{myBean.tabs}" var="t">

        <rich:tab id="tab_#{t.code}" header="#{t.libelle}" name="#{t.code}" >

            <!--  ############ HEADER ############ -->
            <rich:dataTable id="tableHeader_#{t.code}">
                <f:facet name="header">
                    <rich:columnGroup>
                       <!-- Some columns. Let's say that I have a button like a sort 
                            with a render attribute set to "tab_#{t.code}"
                            Then all will be correctly rendered but 
                            the get of my collection would have been called 15 times -->
                   </rich:columnGroup>
                </f:facet>
            </rich:dataTable>

            <!--  ############ DATA ############ -->
            <rich:dataTable id="tableData_#{t.code}" value="#{myBean.collectionOfItems}" var="i">
                <!-- Some columns -->
            </rich:dataTable>

        </rich:tab>
    </c:forEach>
</rich:tabPanel>

提前谢谢你!

【问题讨论】:

  • 15 次迭代 = 15 次调用。不过,调用 getter 的次数并不重要。
  • 这很重要,因为它没有任何意义(我有一个我怀疑与此有关的问题):我可能有 15 次迭代来构建选项卡,但只有活动的选项卡有内容,因此数据表。所以getCollectionOfItems应该只调用一次,否则哪里有问题。
  • 毫无意义不是客观问题。对你的申请有影响吗? c:forEach 发生在标签呈现之前,但即使您的标签是静态的,getter 仍可能被多次调用。

标签: jsf tabs richfaces javabeans


【解决方案1】:

生成称为 15 是因为应该生成选项卡标题(标题方面)。但是,如果你想做一些 #{myBean.selectedTab} 特定的事情,请检查一下(或类似的事情):

<c:forEach items="#{myBean.tabs}" var="t">
  <c:if test="#{t.equals( myBean.selectedTab )}" >
    ...
  </c:if>

【讨论】:

  • 不,如果我这样做,只会呈现活动选项卡。就像我在标签标签上使用渲染属性一样。
  • 此外,我尝试在 dataTable 标记上使用渲染属性,但它没有任何改变,因为正如我所说,默认情况下 DOM 仅包含活动选项卡的表。其他标签没有任何子标签,所以我真的不明白为什么多次调用 get 方法。
猜你喜欢
  • 1970-01-01
  • 2012-09-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多