2012-09-29 26 views
6
<ui:define name="description" rendered="false"> 
    <meta name="description" content="do not render" /> 
</ui:define> 

我在我的xhtml頁面中使用此代碼時,當我運行應用程序時,元描述仍然呈現。我想根據一些條件使用元描述標籤。主佈局:ui:使用rendered =「false」屬性定義仍然呈現

<html xmlns="http://www.w3.org/1999/xhtml" 
     xmlns:ui="http://java.sun.com/jsf/facelets" 
     xmlns:h="http://java.sun.com/jsf/html"> 
    <h:head> 
     <ui:insert name="description" /> 
    </h:head> 
    ........... 
</html> 

網頁:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"      
       xmlns:ui="http://java.sun.com/jsf/facelets" 
       xmlns:h="http://java.sun.com/jsf/html" 
       xmlns:f="http://java.sun.com/jsf/core" 
       xmlns:p="http://primefaces.org/ui" 
       template="/templates/masterLayout.xhtml"> 

    <ui:define name="description" rendered="false"> 
     <meta name="description" content="do not render" /> 
    </ui:define> 
........... 
</ui:composition> 

回答

13

<ui:define>是在視圖編譯時間運行taghandler,不哪個視圖中運行的UIComponent渲染時間。因此它確實支持rendered屬性not。任何不受支持的屬性都會被忽略。

改爲使用<ui:fragment>

<ui:define name="description"> 
    <ui:fragment rendered="false"> 
     <meta name="description" content="do not render" /> 
    </ui:fragment> 
</ui:define> 
相關問題