7

I have numeric values in a p:dataTable. When the value is less than 0, a "-" symbol should be inserted instead of a value.

I tried using c:if, which doesn't work. I was reading and people suggest the rendered flag.

The code is:

<p:column headerText="Valor">
    <h:outputText rendered="${valor.valor > 0}" value="${valor.valor}" />
    <h:outputText rendered="${valor.valor <= 0}" value="${valorMB.noDato}" />
</p:column>

and the server give me this error:

The value of attribute "rendered" associated with an element type "h:outputText" must not contain the '<' character

If I use c:if the table appears without data:

<c:if test="#{valor.valor > 0}">
    <h:outputText value="#{valor.valor}" />
    <c:otherwise>
        <h:outputText value="-" />
    </c:otherwise>
</c:if>  

How can I resolve my problem?

4

2 回答 2

17

使用基于关键字的 EL 运算符而不是基于符号的 EL 运算符:

<h:outputText rendered="#{valor.valor gt 0}" value="#{valor.valor}" /> <!-- valor.valor > 0 -->
<h:outputText rendered="#{valor.valor le 0}" value="-" /> <!-- valor.valor <= 0 -->
  • lt(低于)
  • gt(比...更棒)
  • le(小于或等于)
  • ge(大于或等于)
  • eq(平等的)
  • ne(不相等)
  • and
  • or
于 2014-12-19T23:44:33.553 回答
2

您收到该错误是因为“<”字符在 xml 中的字符串中是非法的。您应该使用表达式语言的比较方式。

在您的情况下,您应该使用lewhich means mean less than or equal

更改 "${valor.valor <= 0}""${valor.valor le 0}"

于 2014-12-19T23:44:07.810 回答