veo*_*ote 2 el composite-component jsf-2
我在WebSphere Application Server 8上使用JSF 2.0(Apache myFaces).
我有一个bean,其中包含一个图表列表(jquery HighCharts的数据).对于每个图表,我需要一些JSF组件+一个写为CompositeCompoent的Highchart Wrapper(在这里查看)
所以我使用jsf 2的ui:repeat函数,如下所示:
<?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>
Run Code Online (Sandbox Code Playgroud)
#{chartStatus.index}适用于hc:Chart id ="".此CC生成的js和div包含id'hcchart_chartdiv'.当前重复的索引离开了.
如何将正确的数字传递给id属性?
编辑:复合组件
以下是应该使用ID的hc:Chart的一部分
<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>
Run Code Online (Sandbox Code Playgroud)
当我将属性id保留在hc:Chart为空时,生成的ID就像"j_id568185923_1_5f9521d0_chartDiv".但仍然没有:行:
编辑2:IndexOf方法我测试了另一种方法来设置我的图表的ID.
id="hc_#{chartCtrl.charts.indexOf(chart) }"
Run Code Online (Sandbox Code Playgroud)
我试图使用我的ArrayList的IndexOf方法.我在所有类中实现了HashCode和Equals方法.当我测试它,它工作正常.但是当我使用EL时,我得到-1返回.
解决方案 正如BalusC所说我不能使用EL的ID标签.所以我在CC中创建了一个新属性.这很好(只是这么容易).
谢谢BalusC.
有人有另一个想法吗?
id在视图构建期间评估该属性.<ui:repeat varStatus>在视图渲染时间期间设置,该时间在视图构建时间之后.基本上,你遇到的问题与这里详细解释的一样:JSF2 Facelets中的JSTL有意义吗?
id在视图构建期间,属性中的任何EL表达式都必须可用.如果要替换<ui:repeat>由<c:forEach>这在视图生成时运行,那么id必须正确设置.另一种方法是在这些id属性的基础上摆脱EL <ui:repeat varStatus>.JSF 已经自动<ui:repeat>使用行索引为子组件的ID添加后缀.
请注意,<c:forEach>当与视图范围bean结合使用并启用部分状态保存时,可能会产生无法预料的副作用.有关详细信息,请参阅上述相关答案.
| 归档时间: |
|
| 查看次数: |
9079 次 |
| 最近记录: |