4

I'm designing the template for my new JSF2.0 App and I want to use the resources folder to store my css-file. Now I started to create a template-file, but I don't know how to link the css.

I tried:

<link rel="stylesheet" type="text/css" href="resources/css/style.css"/>

..but didn't work

Can somebody help me, pls. THX


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

That doesn't work either :-(


It still doesn't work! Maybe that resource-method is disabled?! It doesn't work with pictures either!

<h:graphicImage value="#{resource['img:logo.png']}"/>

The output in my browser looks like that:

<img src="RES_NOT_FOUND">

EDIT: Images working now. I stupidly set a wrong path -.- but the stylesheet is still not working

Sven
  • 6,288
  • 24
  • 74
  • 116

6 Answers6

6

Make sure you have h:head/h:body tags.

mikalaj
  • 111
  • 1
5

You need to put public resources in the public webcontent (/webapp folder as on your screenshot). CSS files are downloaded/included by webbrowser, not by webserver and hence need to be directly public accessible.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thank you for that information. But I have another question: Maven (that I use) wants a folder named 'resources' under src/main. What is that folder for? I thought that's the folder for resources. cheers – Sven Jul 15 '10 at 11:32
2

Create a sub-directory resources at the web application root and try. It will work.

Please refer to http://docs.oracle.com/javaee/6/tutorial/doc/girgm.html

Sita Ram
  • 21
  • 1
0

I had the same problem everything work after switching those two lignes :

from :

xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"

to :

xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
Juskie
  • 67
  • 1
  • 12
0

It works with plain old html:

<link href="./resources/css/style.css" rel="stylesheet" type="text/css" />

But i don't like it I would prefer JSF...

Sven
  • 6,288
  • 24
  • 74
  • 116
-2
<h:outputStylesheet library="css" name="style.css"  />

Please check the link below: Reference to CSS under resources folder in jsf.

https://examples.javacodegeeks.com/enterprise-java/jsf/outputstylesheet-example-with-jsf-2-0/

Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
  • This is not the way to do it, See https://stackoverflow.com/questions/11988415/what-is-the-jsf-resource-library-for-and-how-should-it-be-used – Kukeltje Jan 31 '19 at 08:54