2011-04-13 35 views
7

我跟一個標題和字幕的JSF模板名稱屬性:Acessing的<ui:insert>

<h3><ui:insert name="title"/></h3> 
<hr/> 
<h5><ui:insert name="subtitle"/></h5> 

所有使用該模板的頁面有標題,但並不總是一個副標題:

<ui:define name="title">My Title with no subtitle</ui:define> 

當沒有字幕時,我不想擁有<hr/>標籤。所以我真正想做的是檢查subtitle是否爲空,如果是的話,忽略代碼塊。類似的東西:

<h3><ui:insert name="title"/></h3> 
<c:if test="#{not empty subtitle}"> 
    <hr/> 
    <h5><ui:insert name="subtitle"/></h5> 
<c:if> 

當然<c:if test="#{not empty subtitle}">,但不起作用。我不知道如何訪問subtitle變量的值。

有什麼想法?

感謝

回答

8

最近你能得到的是定義字幕爲<ui:param>代替。

因此,

<ui:define name="title">My Title with a subtitle</ui:define> 
<ui:param name="subtitle" value="A subtitle" /> 

<h3><ui:insert name="title"/></h3> 
<ui:fragment rendered="#{not empty subtitle}"> 
    <hr/> 
    <h5>#{subtitle}</h5> 
</ui:fragment>