【发布时间】: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