JSF not null condition [duplicate]
Asked Answered
L

1

7

Using JSF & EL, I'm basically trying to check if a variable is null (or not).

Here is a code snippet:

<p:dataGrid value="#{bean.graphiques}"
            var="graphique"
            rows="1" columns="3">
    <c:if test="#{not empty graphique}">
        <p:chart type="line" model="#{graphique}"/>
    </c:if>
    <c:if test="#{empty graphique}">
        <p:outputLabel>
            Add a new chart.
        </p:outputLabel>
    </c:if>
</p:dataGrid>

First check, #{not empty graphique} is always false, even if graphique is not null. I tried with #{graphique ne null} and #{graphique != null}, but it's false, too.

When I remove the c:if statement, the chart is displayed. Thus, graphique is not null.

I looked for a solution on a lot of websites - including SO - but didn't manage to find a solution.

Do you know what's going on and how to solve my problem?

Thanks!

Leschen answered 13/6, 2017 at 7:24 Comment(3)
Thanks to @BalusC, I understand what my problem actually is. I'll try to fix it, then post a correct answer.Leschen
Abrikot, it's already answered.Allergy
Well, I thought I had already tried Raul Cuth's answer. But apparently no. I'm sorry!Leschen
H
13

Did you try...

<p:chart type="line" model="#{graphique}" rendered="#{graphique != null}"/>

Sometimes I had issues with primefaces tags in <c:if>

Hydromancy answered 13/6, 2017 at 7:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.