在JSF/XHTML中使用Foreach [英] Using foreach into jsf / xhtml
问题描述
好吧
我排列了一个dataTable,其中必须有一些动态列.... 因此,我正在使用dataTable ...就像上面的代码一样:
I array a dataTable where i must have some dynamic columns.... So im using dataTable... Like the code above:
<rich:dataTable value="#{query.dataModel}" var="inscricao">
<rich:column label="My List">
<f:facet name="header">
<h:outputText value="My List" />
</f:facet>
<h:outputText value="#{query.presencas.size()}" />
</rich:column>
<c:forEach var="presenca" items="${query.presencas}">
<rich:column label="Presença">
<f:facet name="header">
<h:outputText value="Presença" />
</f:facet>
<h:outputText value="testing" />
</rich:column>
</c:forEach>
</rich:dataTable>
好吧,我的问题是我的foreach无法正常工作. 我的列表"列正确显示了列表中我具有的元素数量.但是当我尝试将其迭代到c:forEach中时,它不起作用...
Well, my problem is that my foreach is not working. The column "My List" shows the number of element i have in the list correctly... But when i try iterating it into c:forEach its not working...
我已经尝试使用:
xmlns:c ="http://java.sun.com/jstl/core"
xmlns:c="http://java.sun.com/jstl/core"
和另外一个:
xmlns:c ="http://java.sun.com/jsp/jstl/core"
xmlns:c="http://java.sun.com/jsp/jstl/core"
但是成功了...也尝试使用ui:repeat这样:
But withotu success... Also tryed using ui:repeat like this:
<ui:repeat value="#{query.presencas}" var="presenca">
<f:facet name="header">
<h:outputText value="#{presenca.id}" />
</f:facet>
</ui:repeat>
但也没有用.
有人知道这可能是问题所在,还是以其他方式迭代列表?
Someone know what can be the problem or some another way to iterate a list?
我看到,如果我在列中使用a4j:repeat,它会在a4j:repeat内识别出我的列.否则,如果我删除a4j:repeat之外的列,则不起作用...
I saw that if i use an a4j:repeat INTO a column, it recognize my column inside the a4j:repeat. Otherwise, if i remove the column outside a4j:repeat it doesnt work...
<rich:column label="Presenças" title="teste" >
<a4j:repeat value="#{query.presencas}" var="presenca">
<rich:column label="Presenças" title="teste" >
<f:facet name="header">
<h:outputText value="Presença" />
</f:facet>
<h:selectBooleanCheckbox value="#{inscricao.credenciamento}" />
</rich:column>
</a4j:repeat>
</rich:column>
推荐答案
在渲染响应阶段评估输出文本组件(value="#{query.presencas.size()}"
)的值.
在构建树上评估forEach标记处理程序(items="${query.presencas}"
)的值.
您正在EL中使用不同的符号来区分($和#).
似乎query.presencas
没有在构建树上初始化.您可以检查构建树上的评估计数:
Value of output text component (value="#{query.presencas.size()}"
) is evaluated on render response phase.
Value of forEach tag handler (items="${query.presencas}"
) is evaluated on build tree.
You are using different symbols in EL to differentiate that ($ and #).
It seems that query.presencas
is not initialized on build tree. You can check that evaluating count on build tree:
<c:set var="count" value="${query.presencas.size()}"/>
<h:outputText value="#{count}"/>
要构建动态列数,您可以使用c:forEach
(如您所做的那样),将在构建树上评估items
属性(例如,当评估items
值时,inscricao
var不可用) ).
使用ui:repeat
它将不起作用,因为RichFaces组件(dataTable,tabPanel和其他组件)无法处理该问题.
To build dynamic number of columns you can use c:forEach
(as you do), items
attribute will be evaluated on build tree (so for example inscricao
var is not available when items
value is being evaluated).
Using ui:repeat
it will not work since RichFaces components (dataTable, tabPanel and others) does not handle that.
这篇关于在JSF/XHTML中使用Foreach的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!