我输入了以下代码:
<h:outputStylesheet library="css" name="style.css" target="body" />
问题是它在 target="body"上给了我一个错误说:
The attribute target is not defined in the component outputStylesheet
在 html 部分,如果 html 我有以下内容:
<html 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"
xmlns:pe="http://primefaces.org/ui/extensions">
我该如何解决这个问题?
谢谢
最佳答案
查看 tag documentation of <h:outputStylesheet>
.它确实没有列出 target
属性。也许您对 <h:outputScript>
中的一个感到困惑.<h:outputStylesheet>
默认为 总是 重新定位到 HTML <head>
,原因很简单,因为拥有 <style>
是非法的或 <link>
HTML 中的元素 <body>
. <h:outputScript>
然而,默认情况下,它与声明的位置完全相同。 <script>
由它生成的元素可以放置在 HTML 中的任何位置 <head>
或 <body>
.您可以通过设置 target
来让 JSF 自动重新定位它。归因于 head
(然后会出现在 <head>
中)或 body
(然后会出现在 <body>
的末尾)。
只需将其删除。如 target="body"
理论上会奏效,但无论如何它只会以非法的 HTML 输出结束。
<h:outputStylesheet library="css" name="style.css" />
无关 对于具体问题,“css”的资源库名称在语义上是错误的。把它放在资源名称中。
<h:outputStylesheet name="css/style.css" />
也可以看看:
关于jsf - Netbeans 错误 "The attribute target is not defined in the component outputStylesheet",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20240302/