Netbeans errors "The attribute target is not defined in the component outputStylesheet"
Asked Answered
Y

1

6

I have entered the following code:

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

The problem is that it is giving me an error on target="body" saying:

The attribute target is not defined in the component outputStylesheet

In the html part if the html I have the following:

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

How can I solve this issue?

Thanks

Ygerne answered 27/11, 2013 at 10:47 Comment(1)
I believe that you don't need to specify the attribute target.Sacellum
U
5

Look in the tag documentation of <h:outputStylesheet>. It indeed doesn't list target attribute. Perhaps you're confusing with the one from <h:outputScript>.

The <h:outputStylesheet> is by default always relocated to HTML <head>, for the very simple reason because it's illegal to have a <style> or <link> element inside the HTML <body>. The <h:outputScript> however is by default located at exactly the same location as where it's been declared. The <script> element as generated by it may be placed anywhere in the HTML <head> or <body>. You can let JSF auto-relocate this by setting the target attribute to head (will then appear in <head>) or body (will then appear in end of <body>).

Just remove it. If target="body" would theoretically have worked, it would only end up in illegal HTML output anyway.

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

Unrelated to the concrete problem, a resource library name of "css" is semantically wrong. Put it in the resource name.

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

See also:

Unknowable answered 27/11, 2013 at 11:3 Comment(4)
The way the OP uses the command is also used in Oracle's JEE7 Tutorial in the jsf/reservation example. So did they have it wrong as well?Zeniazenith
Yes, it is incorrect in the JavaEE tutorial: <h:outputStylesheet name="css/stylesheet.css" target="head"/>. Here: docs.oracle.com/javaee/7/tutorial/jsf-facelets009.htmByerly
Also, the JavaEE tutorial examples contain this line as well... (reservation example)Byerly
@AVC: it's currently already fixed. They don't use library="css" anymore.Unknowable

© 2022 - 2024 — McMap. All rights reserved.