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

1 回答 1

16

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

改为使用<ui:fragment>

<ui:define name="description">
    <ui:fragment rendered="false">
        <meta name="description" content="do not render" />
    </ui:fragment>
</ui:define>
于 2012-09-29T21:52:34.800 回答