使用ui:composition模板时如何自定义h:head? [英] How to customize h:head when using ui:composition template?

查看:144
本文介绍了使用ui:composition模板时如何自定义h:head?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JSF呈现HTML页面.我像这样设计页面:

I am using JSF to render an HTML page. I design the page like it :

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

此模板具有一些客户端"页面,例如:

This template has some "client" pages, like this one :

<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"标记中呈现,那就太好了.

In the client, i have to add meta information in the header. It would be great if we have tag like outputScript or outputStylesheet which can be set everywhere in the document and rendered in the html "head" tag.

我什么也没做.在这种情况下,是否可以在标头中添加标签? 谢谢!

I have found nothing to do this. Is there a way to add tag in the header when i am in this situation ? Thank you !

推荐答案

<h:outputStylesheet>总是自动重定位到<h:head>,因此您不必为此担心.对于<h:outputScript>(默认情况下,它与声明的位置在同一行呈现),您可以将target属性设置为head,这样,它也会自动重定位到<h:head>. /p>

The <h:outputStylesheet> is always automatically relocated to <h:head>, so you don't need to worry about this. For <h:outputScript>, which is by default rendered at the same line as where it's been declared, you can just set the target attribute to head, this way it will automatically be relocated to the <h:head> as well.

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

对于其他HTML标头元信息,由于某种原因在必要时,您可以声明另一个<ui:insert>.

For other HTML head meta information, whenever necessary for some reason, you could just declare another <ui:insert>.

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

您可以按以下方式使用

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

另请参见:

  • 如何引用CSS/JS/图像资源在Facelets模板中?
  • See also:

    • How to reference CSS / JS / image resource in Facelets template?
    • 这篇关于使用ui:composition模板时如何自定义h:head?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆