ui:define with rendered =“false”属性仍然呈现

时间:2012-09-29 18:54:34

标签: jsf facelets

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

我在我的xhtml页面中使用此代码,当我运行应用程序时,元描述仍在呈现。我想根据某些条件使用元描述标签。主布局:

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

1 个答案:

答案 0 :(得分:16)

<ui:define>是一个在视图构建时运行的标记处理程序,而不是在视图渲染时运行的UIComponent。因此,not支持rendered属性。任何不受支持的属性都会被忽略。

改为使用<ui:fragment>

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