gpt4 book ai didi

jsf - 如何自定义 h :head when using ui:composition template?

转载 作者:行者123 更新时间:2023-12-04 00:39:22 25 4
gpt4 key购买 nike

我正在使用 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” 标签中呈现,那就太好了。

我发现没有什么可以做到这一点。当我处于这种情况时,有没有办法在标题中添加标签?
谢谢 !

最佳答案

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

也可以看看:
  • How to reference CSS / JS / image resource in Facelets template?
  • 关于jsf - 如何自定义 h :head when using ui:composition template?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11545210/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com