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?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Pablo Aleman
  • 196
  • 1
  • 3
  • 13
  • Should use # in rendered="#{valor.valor > 0}". The property valor must be an int. The value of the h:outputText in valor <= 0 should be the - character you want to show. – Kaz Miller Dec 19 '14 at 23:26

2 Answers2

17

Use keyword based EL operators instead of symbol based EL operators:

<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 (lower than)
  • gt (greater than)
  • le (lower than or equal)
  • ge (greater than or equal)
  • eq (equal)
  • ne (not equal)
  • and
  • or
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Kaz Miller
  • 949
  • 3
  • 22
  • 40
2

You are getting that error because "<" character is illegal in string inside xml. You should use Expression Language way of comparing.

In your situtation you should use le which means means less than or equal.

Change "${valor.valor <= 0}" to "${valor.valor le 0}"

Salih Erikci
  • 5,076
  • 12
  • 39
  • 69