在JSF

2011-12-06 48 views
7

我想根據條件 改變變量值條件變量的定義,所以我嘗試了以下內容:在JSF

<h:head> 

    <ui:param name="userCase" value="Insert" /> 

    <ui:fragment rendered="#{employee.employeesBulkInsert==false}"> 
     <ui:param name="userCase" value="Update" /> 
    </ui:fragment> 

     <title>#{userCase} Employee </title> 

</h:head> 

,但它不更新的情況下工作,它顯示了一個空字符串,任何想法爲什麼?

我知道還有其他的解決方案,像在後臺bean中定義變量,或直接在標題標籤上製作條件ui片段,但我想知道爲什麼上述不起作用,請告知,謝謝。

+0

這是非常好的做法,說你遇到什麼樣的行爲(錯誤?有什麼消息嗎?不是你所期望的輸出是什麼?你期待?),而不僅僅是「不起作用」。 – Gian

+0

當然,我會更新問題:) –

回答

13

<ui:fragment>被渲染時標籤,而<ui:param>是一個標籤處理器(標記處理程序很容易recognizeable因缺乏的rendered屬性)。因此,視圖生成時,無論<ui:fragment>的結果如何,都會設置<ui:param><ui:fragment>rendered屬性僅在已經構建的視圖被渲染時才被評估。

您希望使用標記處理程序來替代條件,例如JSTL <c:if>

<ui:param name="userCase" value="Insert" /> 

<c:if test="#{not employee.employeesBulkInsert}"> 
    <ui:param name="userCase" value="Update" /> 
</c:if> 

(注意,我刪除了不必要的布爾==false比較)