Netbeans错误"属性目标未在组件outputStylesheet中定义"

kei*_*eri 6 jsf netbeans facelets

我输入了以下代码:

<h:outputStylesheet library="css" name="style.css" target="body" />
Run Code Online (Sandbox Code Playgroud)

问题是它给我一个关于target ="body"的错误说:

The attribute target is not defined in the component outputStylesheet
Run Code Online (Sandbox Code Playgroud)

在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">
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?

谢谢

Bal*_*usC 5

查看标签文档<h:outputStylesheet>.它确实没有列出target属性.也许你和那个人混淆了<h:outputScript>.

在<h:outputStylesheet>默认情况下,始终搬迁到HTML <head>中,原因很简单,因为它是非法的一个<style>或<link>元素的HTML中<body>.该<h:outputScript>然而,在默认情况下位于完全相同的位置,因为它一直宣称在哪里.<script>由它生成的元素可以放在HTML <head>或中的任何位置<body>.您可以让JSF通过将target属性设置为head(将显示在其中<head>)或body(然后将显示在结尾<body>)来自动重定位.

只需删除它.如果target="body"理论上有效,那么无论如何都只会导致非法的HTML输出.

<h:outputStylesheet library="css" name="style.css" />
Run Code Online (Sandbox Code Playgroud)

与具体问题无关,资源库名称"css"在语义上是错误的.把它放在资源名称中.

<h:outputStylesheet name="css/style.css" />
Run Code Online (Sandbox Code Playgroud)

也可以看看:

  • OP使用该命令的方式也在jsf/reservation示例中的Oracle JEE7教程中使用.他们也错了吗? (3认同)