C:里面的foreach ^ h:数据表显示二维数组 [英] c:foreach inside h:datatable to show two dimensional array

查看:145
本文介绍了C:里面的foreach ^ h:数据表显示二维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用H:数据表标签来显示二维int数组的值。但不能做到这一点。能不能帮我一个解决方案?

I am trying to use h:datatable tag to display values of two-dimensional int array. But cannot make it. Could help me with a solution?

所以,我支持bean是:

So my backing bean is:

public class MC {
...........

public int[][] getAr() {
    return ar;
}

public int getColCount(){
    return ar[0].length;
}
}

我可以显示与code中的foreach标签指的是数组大小数组:

I can display the array with code in foreach tag referring to the array size:

<h:dataTable value="#{mC.ar}" var="dt">
<c:forEach var="fe" begin="0" end="#{mC.colCount-1}">
    <h:column>
        <f:facet name="header">X</f:facet>
            #{dt[fe]}
    </h:column>
</c:forEach> 
</h:dataTable>

但是,如果我尝试使用变量从dataTable中印什么:

But nothing is printed if I try to use variable from dataTable:

 <h:dataTable value="#{mC.ar}" var="dt">
 <c:forEach var="fe" items="#{dt}">
    <h:column>
        <f:facet name="header">XX</f:facet>
            #{fe}
    </h:column>
</c:forEach> 
</h:dataTable>

你能不能帮我做工作?或者,也许你可以建议一些更好的解决方案可以显示阵列?谢谢

Could you help me to make it work? Or perhaps you could suggest some better solution to display an array? Thank you

推荐答案

有在假设做得比较常见的错误,C:的forEach在DataTable的迭代处理的同时进行处理。 C:的forEach在构建JSF树处理一次,在这个阶段没有定义DT变量。 H:dataTable的定义JSF的DT变量恢复/渲染阶段。使用UI:重复而不是C:如果你需要在这个阶段进行迭代的forEach

There is quite common mistake done in assumption that c:forEach is processed in the same time the iteration of dataTable is processed. c:forEach is processed once in build JSF tree, in this phase there is NO "dt" variable defined. h:dataTable defines the "dt" variable in JSF restore/render phases. Use the ui:repeat instead of c:forEach if you need to iterate in this phases.

这篇关于C:里面的foreach ^ h:数据表显示二维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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