Jsf 2 UI Repeat varStatus在CompositeComponent中不工作
我在WebSphereApplicationServer8上使用JSF2.0(ApacheMyFaces) 我有一个bean,它包含一个图表列表(jqueryhighcharts的数据)。 对于每个图表,我需要一些JSF组件+一个编写为CompositeComponent()的Highchart包装器 因此,我使用jsf 2的ui:repeat函数如下:Jsf 2 UI Repeat varStatus在CompositeComponent中不工作,jsf-2,el,composite-component,Jsf 2,El,Composite Component,我在WebSphereApplicationServer8上使用JSF2.0(ApacheMyFaces) 我有一个bean,它包含一个图表列表(jqueryhighcharts的数据)。 对于每个图表,我需要一些JSF组件+一个编写为CompositeComponent()的Highchart包装器 因此,我使用jsf 2的ui:repeat函数如下: <?xml version="1.0" encoding="UTF-8" ?> <u
<?xml version="1.0" encoding="UTF-8" ?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:hc="http://java.sun.com/jsf/composite/chartComponents"
template="/template/mytemplate.xhtml">
<ui:define name="content">
<ui:repeat value="#{chartCtrl.charts }" var="chart" id="chartrepeat" varStatus="chartStatus">
#{chartStatus.index }
<h:form id="chartform_#{chartStatus.index }">
<!-- some jsf select stuff-->
</h:form>
#{chartStatus.index }
<hc:Chart title="Statistics" id="hcchart_#{chartStatus.index }"
<!-- here's the problem-->
<ui:repeat value="#{chart.series }" var="serie">
<hc:ChartSeries series="#{serie.data }" />
</ui:repeat>
</hc:Chart>
#{chartStatus.index }
</p:panel>
</ui:repeat>
<h:outputScript library="js" name="highcharts.js" />
<h:outputScript library="js/modules" name="exporting.js" />
<h:outputScript library="js" name="jquery-1.9.1.min.js" target="head" />
</ui:define>
</ui:composition>
我尝试使用ArrayList的IndexOf方法。我在所有类中实现了HashCode und Equals方法。当我测试它时,它运行良好。
但是当我用EL时,我得到了-1返回
解决方案
正如巴卢斯克所说,我不能把身份证标签用在EL上。所以我简单地在我的CC中创建了一个新属性。那很好(就是这么简单)
谢谢你,巴卢斯克
有人有其他想法吗?在视图构建期间评估
id
属性。
在视图生成时间之后的视图渲染时间内设置。本质上,您遇到了与此处详细解释的相同的问题:
id
属性中的任何EL表达式必须在视图生成期间可用。如果将
替换为在视图生成期间运行的
,则必须正确设置id
。另一种方法是基于
在那些id
属性中去掉EL。JSF将已经自动为
子组件的ID添加行索引后缀
请注意,
与视图范围的bean和启用的部分状态保存结合使用时,可能会产生不可预见的副作用。有关详细信息,请参阅上述链接的答案。感谢您的回复。当我使用c:forEach时,我会得到一个outoufmemory例外(堆空间)。但我不知道为什么。在我的例子中,图表呈现到的div没有得到:row:,因为它是一个硬编码的id。你有别的想法吗?它是递归地包含的吗?您应该使用树组件,如
或无标记
。或者只需通过从ID
属性中删除任何EL来利用JSF的唯一ID自动生成。
<cc:implementation>
<div id="#{cc.id}_chartDiv" />
<!-- Highcharts -_>
<script type="text/javascript">
$(function() {
// Data must be defined WITHIN the function. This prevents
// different charts using the same data variables.
var options = {
credits : {
enabled : false
},
chart : {
renderTo : '#{cc.id}_chartDiv',
....
</script>
id="hc_#{chartCtrl.charts.indexOf(chart) }"