< c:when>在PrimeFaces数据表中无法正常工作? [英] <c:when> not working in PrimeFaces datatable?

查看:70
本文介绍了< c:when>在PrimeFaces数据表中无法正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做的是对表的第一行,第二行等进行操作.

What I'm trying to do is do something to the first row, second row, etc. of the table.

<p:panel header="#{mat.description}">
    <p:dataTable var="datarow" value="#{myBean.getDatarows(mat.itemId)}" emptyMessage="No materials" rowIndexVar="row">
        <c:choose>
            <c:when test="${row eq 0}">
                <p:column headerText=""><h:outputText value="#{datarow.get(1)}" /></p:column>
            </c:when>
            <c:when test="${row eq 1}">
                <p:column headerText=""><h:outputText value="#{datarow.get(1)}" /></p:column>
            </c:when>
        </c:choose>
        <p:column headerText=""><h:outputText value="#{datarow.get(6)}" /></p:column>
        <p:column headerText="Month 1"><h:outputText value="#{datarow.get(1)}" /></p:column>
        <p:column headerText="Month 3"><h:outputText value="#{datarow.get(2)}" /></p:column>
        <p:column headerText="Month4"><h:outputText value="#{datarow.get(3)}" /></p:column>
        <p:column headerText="Month 5"><h:outputText value="#{datarow.get(4)}" /></p:column>
        <p:column headerText="Month6"><h:outputText value="#{datarow.get(5)}" /></p:column>
    </p:dataTable>
</p:panel>

但是c:choose和c:w何时未显示任何内容.我对行号的测试有误吗?

But the c:choose and c:when is not displaying anything. Am I doing the test for row number wrongly?

推荐答案

这是错误的设计,因此无法正常工作.您以错误的方式混淆了JSTL和JSF标签.

This is bad design and will not work that way. You are mixing up JSTL and JSF tags in a wrong way.

在树构建期间评估JSTL标签c:choosec:when,但是在呈现UI树时评估p:dataTable标签.

The JSTL tags c:choose and c:when are evaluated during tree built, but the p:dataTable tag when the UI tree is rendered.

如果要包括/排除数据表的完整列,只需使用p:column上的rendered属性.如果要在 列中显示蜂鸣的行为不同,例如,可以使用? -operator来确定蜂鸣的呈现方式:

Just use the rendered-attribute on p:column instead, if you want to include/exclude complete columns of your datatable. If you want to achieve different behavior of what is beeing displayed inside the columns, you could for example use the ?-operator to decide what is beeing rendered:

<p:dataTable var="datarow" ... rowIndexVar="row">
    <p:column>
        <h:outputText value="#{row eq 0 ? datarow.get(1) : 'some other stuff'}"/>
    </p:column>
</p:dataTable>


要在您的列中呈现不同种类的元素,只需将它们都放入列中,但要使用不同的rendered -attribute:


To render different kind of elements inside your column, just put both of them inside the column, but with different rendered-attribute:

<p:column>
        <h:outputText rendered="#{row != 4}"/>
        <p:inputText rendered="#{row eq 4}"/>
</p:column>

这将在第5行中呈现一个input-element(rowIndexVar基于0),在所有其他行中呈现一个output-element.

This will render an input-element in the 5th row (rowIndexVar is 0-based), and an output-element in all other rows.

这篇关于&lt; c:when&gt;在PrimeFaces数据表中无法正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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