14

JSFを使用してHTMLページをレンダリングしています。私はそれのようにページをデザインします:

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

<h:head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <meta name="language" content="fr" />
    <title><ui:insert name="title">My app</ui:insert></title>
</h:head>

<h:body>
    <div id="top">
        <ui:include src="/header.xhtml"/>
    </div>

    <h:panelGroup id="center" layout="block" >
        <ui:insert name="center"/>
    </h:panelGroup>

    <div id="bottom">
        <ui:include src="/footer.xhtml"/>
    </div>
</h:body>

このテンプレートには、次のようないくつかの「クライアント」ページがあります。

<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="/layouts/master.xhtml">

<ui:define name="center">
    <ui:define name="title"><h:outputText value="#{myBean.description}"/></ui:define>
    <ui:include src="#{myBean.url}"/>
</ui:define>

クライアントでは、ヘッダーにメタ情報を追加する必要があります。outputScriptやoutputStylesheetのようなタグがあれば、ドキュメントのどこにでも設定でき、htmlの「head」タグでレンダリングできると便利です。

私はこれをするために何も見つけませんでした。この状況でヘッダーにタグを追加する方法はありますか?ありがとうございました !

4

1 に答える 1

22

<h:outputStylesheet>常に自動的にに再配置されるため<h:head>、これについて心配する必要はありません。は<h:outputScript>、デフォルトで宣言された場所と同じ行にレンダリングされますが、target属性をに設定するだけheadで、このように自動的にに再配置さ<h:head>れます。

<ui:define name="center">
    <h:outputStylesheet name="css/style.css" />
    <h:outputScript name="js/script.js" target="head" />
    ...
</ui:define>

他のHTMLヘッドのメタ情報については、何らかの理由で必要な場合はいつでも、別のを宣言することができます<ui:insert>

<h:head>
    <ui:insert name="htmlhead" />
</h:head>

次のように使用できます

<ui:define name="htmlhead">
    <meta ... />
</ui:define>

参照:

于 2012-07-18T16:06:49.307 に答える