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

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
keith Spiteri
  • 259
  • 1
  • 6
  • 22

1 Answers1

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:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • 3
    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? – Alexander Rühl Apr 01 '14 at 09:38
  • Yes, it is incorrect in the JavaEE tutorial: ``. Here: https://docs.oracle.com/javaee/7/tutorial/jsf-facelets009.htm – ACV Mar 31 '16 at 09:33
  • Also, the JavaEE tutorial examples contain this line as well... (reservation example) – ACV Mar 31 '16 at 09:35
  • @AVC: it's currently already fixed. They don't use `library="css"` anymore. – BalusC Mar 31 '16 at 09:35