2017-06-13 43 views
0

使用JSF & EL,我基本上試圖檢查一個變量是否爲空(或不)。JSF不爲空條件

下面的代碼片段:

<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> 

首先檢查,#{not empty graphique}永遠是假的,即使graphique不爲空。我嘗試了#{graphique ne null}#{graphique != null},但它也是錯誤的。

當我刪除c:if語句時,會顯示圖表。因此,graphique不爲空。

我在很多網站上尋找解決方案 - 包括SO - 但沒有設法找到解決方案。

你知道發生了什麼事以及如何解決我的問題?

謝謝!

+0

感謝@BalusC,我明白我的問題實際上是。我會嘗試修復它,然後發佈一個正確的答案。 – Abrikot

+0

Abrikot,它已經回答了。 – BalusC

+0

嗯,我以爲我已經嘗試了勞爾Cuth的答案。但顯然沒有。對不起! – Abrikot

回答

3

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

有時候,我曾與primefaces標籤問題<c:if>

+0

我試過了,但是當'graphique'不爲空時崩潰了...... – Abrikot

+0

顯然,我還沒有試過你的答案。 (也許類似的東西沒有用?)。感謝您的回答! – Abrikot