带richfaces的动态列4 [英] Dynamic columns with richfaces 4

查看:131
本文介绍了带richfaces的动态列4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要动态列数. Richfaces在Richfaces 3.3.3-final中为其提供了<rich:columns>,但对于Richfaces 4,他们似乎建议使用<c:forEach>.

I need dynamic number of columns. Richfaces supplies it with <rich:columns> in richfaces 3.3.3-final but for Richfaces 4 they seem to recommend <c:forEach>.

c:forEach

我无法使其正常工作.由于我不能依赖数据表中的var,因此我无法弄清楚如何用正确的列列表来填充<c:forEach>. (每行都有自己的值,但标题相同)

I can't get it to work properly.Since I can't depend on the var from the datatable I can't figure out how to feed <c:forEach> with the correct list of columns. (Each row has their own values but headers are the same)

基本上,我要显示的数据是x大小的行的列表,每行都有y大小的列值的列表.但是<c:forEach>怎么能告诉backing bean它在哪一行,以便我可以输入正确的列?

Basically the data I want to display is a list with rows of x size, each row has a list of column values with y size. But how can have <c:forEach> tell the backing bean what row it's at so I can feed the correct columns?

ui/a4j:repeat

我不想重新发明轮子,因为我需要冻结的色谱柱和许多其他功能.已经考虑过以这种方式创建表格html并将jQuery用于其他功能.但是,这将是无法维持和进行大量工作的.

I dont want to reinvent the wheel because I need frozen columns and many other features. Creating the table html this way and use jQuery for other features have been considered. However this would be hopeless to maintain and to much work.

我还研究了从支持bean构造它来动态创建子对象,但我一点都不喜欢.这将是最后的手段.

I also looked at constructing it from the backing bean creating children dynamically but I don't like that at all. This would have to be the last resort.

使用:Tomcat 7,Servlet 3.0,JSF 2.1x-Mojarra,Richfaces 4.x

Using: Tomcat 7, servlet 3.0, JSF 2.1x - Mojarra, Richfaces 4.x

更新

好的,最后我得到了一些结果.但是我的标题没有显示.值显示完美,但不显示标题.进行迭代时可能会遇到问题吗?

Okay so I'm getting some results finally. However my headers don't show. The values show perfectly but not the headers. Some problem doing them with iteration or something perhaps?

    <rich:dataTable value="#{controller.rows}"
        var="row">
        <c:forEach items="#{controller.columns}" var="column">
            <rd:column id="name" width="250">
                <f:facet name="header">
                    <h:outputText value="#{row.myArrayList[column].header}" />
                </f:facet>
                <h:inputText value="#{row.myArrayList[column].value}"  disabled="#{row.myArrayList[column].open}"/>
            </rd:column>
        </c:forEach>
    </rich:dataTable>

推荐答案

<c:forEach>确实是最好的选择. <ui/a4j:repeat>不能在视图渲染期间运行,而UIData组件确实需要UIColumn子级,而不是UIRepeat子级.

The <c:forEach> is indeed best what you can get. The <ui/a4j:repeat> won't work as that runs during view render time while the UIData component really needs UIColumn children, not UIRepeat children.

为了使<c:forEach>正常工作,您需要向其提供所有属性名称的列表/映射(并且在映射的情况下,还可能包含标题标签).这是一个具体的启动示例,假设Item具有属性idnamevalue,并且#{bean.itemPropertyNames}返回的List<String>具有确切的属性名称.

In order to get the <c:forEach> to work, you need to supply it a list/map of all property names (and in case of a map maybe also header labels). Here's a concrete kickoff example assuming that Item has properties id, name and value and that #{bean.itemPropertyNames} returns a List<String> with exactly those property names.

<rich:dataTable value="#{bean.items}" var="item">
    <c:forEach items="#{bean.itemPropertyNames}" var="itemPropertyName">
        <rich:column>
            #{item[itemPropertyName]}
        </rich:column> 
    </c:forEach>
</rich:dataTable>

如果还需要显示列标题,那么最好使用Map<String, String>,其中键代表属性名称,值代表标题值.

If you need to show column headers as well, then best is to have a Map<String, String> where the key represents the property name and the value represents the header value.

<rich:dataTable value="#{bean.items}" var="item">
    <c:forEach items="#{bean.itemProperties}" var="itemProperty">
        <rich:column>
            <f:facet name="header">#{itemProperty.value}</f:facet>
            #{item[itemProperty.key]}
        </rich:column> 
    </c:forEach>
</rich:dataTable>

无论哪种方式,唯一的缺点是<c:forEach items>#{bean}在此构造中不能成为视图范围的视图.除非您关闭部分状态保存,否则它将在每个请求上重新创建.它必须是一个范围限定的请求(或会话或应用程序).请注意,它不一定要与<rich:dataTable value>中的bean是同一bean.

Either way, the only disadvantage is that the #{bean} of <c:forEach items> can in this construct not be a view scoped one. It would be recreated on every request, unless you turn off partial state saving. It needs to be a request scoped one (or session or application). Note that it does not necessarily need to be the same bean as the one in <rich:dataTable value>.

这篇关于带richfaces的动态列4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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