UI重复varStatus在CompositeComponent中不起作用 [英] UI Repeat varStatus not working in CompositeComponent

查看:71
本文介绍了UI重复varStatus在CompositeComponent中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在WebSphere Application Server 8上使用JSF 2.0(Apache myFaces).

I use JSF 2.0 (Apache myFaces) on WebSphere Application Server 8.

我有一个包含图表列表的bean(jquery HighCharts的数据). 对于每个图表,我需要一些JSF组件+一个写为CompositeCompoent的Highchart包装器(

I have a bean which contains a list of charts (data for jquery HighCharts). For each chart I need some JSF components + one Highchart Wrapper written as CompositeCompoent (look here)

所以我像这样使用jsf 2的ui:repeat函数:

So I use the ui:repeat function of jsf 2 like this:

<?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>

#{chartStatus.index}可以在所有地方工作,但不适用于hc:Chart id =". 此CC生成的js和div包含id'hcchart_chartdiv'.当前重复的索引向左.

The #{chartStatus.index } works every where but not in hc:Chart id="". The generated js and div by this CC contains the id 'hcchart_chartdiv'. The index of the current repeat left.

如何将正确的数字传递给id属性?

How can I pass the correct number to the id attribute?

复合组件

这是hc:Chart的一部分,应在其中使用ID

Here is a part of the hc:Chart where the ID should be used

<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>

当我将hc:Chart中的属性ID保留为空时,则生成的ID类似于"j_id568185923_1_5f9521d0_chartDiv".但仍然没有:row:.

When I leave the attribute id in hc:Chart empty, then the generated ID is something like "j_id568185923_1_5f9521d0_chartDiv". But still without :row:.

IndexOf方法 我测试了另一种设置图表ID的方法.

EDIT 2: IndexOf Approach I tested another approach to set the ID of my chart.

id="hc_#{chartCtrl.charts.indexOf(chart) }"

我尝试使用ArrayList的IndexOf方法.我在所有类中实现了HashCode和Equals方法.当我测试它时,它工作正常. 但是当我将其与EL结合使用时,我会得到-1.

I tried to use the IndexOf method of my ArrayList. I implemented HashCode und Equals method in all Classes. When I test it, it works fine. But when I use it with EL I get -1 returned.

解决方案 就像BalusC所说的那样,我不能为EL使用ID标签.因此,我简单地在CC中创建了一个新属性.效果很好(就这么简单).

Solution Just as BalusC said I cant use the ID tag for EL. So I simple created a new attribute in my CC. That works fine (just so easy).

感谢BalusC.

有人有另一个主意吗?

推荐答案

在视图构建期间评估id属性. <ui:repeat varStatus>在视图渲染时间(在视图构建时间之后 之后)设置.本质上,您将遇到与此处详细说明的问题相同的问题:JSF2 Facelets中的 JSTL.合理吗?

The id attribute is evaluated during view build time. The <ui:repeat varStatus> is set during view render time which is after view build time. Essentially, you've the same problem as explained in detail here: JSTL in JSF2 Facelets... makes sense?

id属性中的任何EL表达式必须在视图构建期间可用.如果将<ui:repeat>替换为在视图构建期间运行的<c:forEach>,则必须正确设置id.一种替代方法是仅基于<ui:repeat varStatus>除去那些id属性中的EL. JSF将已经自动在<ui:repeat>子组件的ID后缀行索引.

Any EL expression in the id attribute must be available during view build time. If you replace <ui:repeat> by <c:forEach> which runs during view build time, then the id must be properly set. An alternative is to just get rid of EL in those id attributes based on <ui:repeat varStatus>. JSF will already automatically suffix the IDs of <ui:repeat> child components with the row index.

请注意,将<c:forEach>与视图范围的Bean结合使用并启用部分状态保存功能时,可能会产生无法预料的副作用.有关详细信息,请参见前面的答案.

Note that the <c:forEach> may have unforeseen side effects when used in combination with view scoped beans and partial state saving enabled. See the aforelinked answer for details.

这篇关于UI重复varStatus在CompositeComponent中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆