【问题标题】:Netbeans errors "The attribute target is not defined in the component outputStylesheet"Netbeans 错误“组件 outputStylesheet 中未定义属性目标”
【发布时间】:2013-11-27 10:47:09
【问题描述】:

我输入了以下代码:

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

我该如何解决这个问题?

谢谢

【问题讨论】:

  • 相信你不需要指定属性target。

标签: jsf netbeans facelets


【解决方案1】:

查看tag documentation of &lt;h:outputStylesheet&gt;。它确实没有列出target 属性。可能你对来自&lt;h:outputScript&gt; 的那个感到困惑。

&lt;h:outputStylesheet&gt; 默认情况下总是重新定位到 HTML &lt;head&gt;,原因非常简单,因为在 HTML &lt;body&gt; 中包含 &lt;style&gt;&lt;link&gt; 元素是非法的.但是,&lt;h:outputScript&gt; 默认位于与声明它的位置完全相同的位置。由它生成的&lt;script&gt; 元素可以放置在HTML &lt;head&gt;&lt;body&gt; 中的任何位置。您可以通过将target 属性设置为head(随后将出现在&lt;head&gt;)或body(随后将出现在&lt;body&gt; 的末尾)来让JSF 自动重定位它。

只需删除它。如果target="body" 理论上可行,那么无论如何它只会以非法的 HTML 输出告终。

<h:outputStylesheet library="css" name="style.css" />

与具体问题无关,资源库名称“css”在语义上是错误的。放在资源名称中。

<h:outputStylesheet name="css/style.css" />

另见:

【讨论】:

  • 在Oracle的JEE7教程中的jsf/reservation示例中也使用了OP使用命令的方式。那么他们也错了吗?
  • 是的,在 JavaEE 教程中是不正确的:&lt;h:outputStylesheet name="css/stylesheet.css" target="head"/&gt;。这里:docs.oracle.com/javaee/7/tutorial/jsf-facelets009.htm
  • 另外,JavaEE 教程示例也包含这一行...(保留示例)
  • @AVC:目前已经修复。他们不再使用library="css"
猜你喜欢
  • 2016-04-14
  • 2012-09-28
  • 1970-01-01
  • 2018-08-24
  • 1970-01-01
  • 1970-01-01
  • 2014-01-12
  • 2019-09-08
相关资源
最近更新 更多