1

I am trying to include my stylesheets within the <h:head> tag utilising the following JSF tag: <h:outputStylesheet name="stylesheets/bootstrap.min.css" />, however when I load my page I get RES_NOT_FOUND for this specific CSS resource when looking through dev tools in the web browser.

I am trying to call the stylesheet within one of my template files I have created, "default.xhtml". Please refer to the image attached below to see my project directory structure, and where the red arrow indicates where the tag is being utilised.

enter image description here

Within the default.xhtml template, I have defined the <h:head> tags although it appears to still not be working. Is there anything I am missing which is not allowing this to be loaded?

If you require more information, please let me know. I would like to resolve this issue as quickly as possible.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Maff
  • 1,032
  • 4
  • 25
  • 42

1 Answers1

2

I figured out the issue here.

By default, I believe that JSF resource handling mechanism does not support for mapping the resource directory which resides in the WEB-INF directory. In order to overwrite this default, you need to explicitly define a new <context-param> within the project web.xml file.

The following fragment of code below specifies the directory used for resource lookup in the file system of the web application.

<context-param> <param-name>javax.faces.WEBAPP_RESOURCES_DIRECTORY</param-name> <param-value>/WEB-INF/resources</param-value> </context-param>

Maff
  • 1,032
  • 4
  • 25
  • 42
  • 1
    Noted should be that this is JSF 2.2 specific. For older JSF versions, you'd still need to move the folder back to its documented place (and if necessary add a security constraint to prevent direct access; this is answered several times before). – BalusC Aug 24 '14 at 05:23
  • @BalusC, appreciate the clarification. On a side note, do you have any of your personal recommended sources for learning the in's and out's of the JSF framework? – Maff Aug 24 '14 at 08:23
  • 1
    Start at https://jsf.zeef.com. By the way, I hope that you're very well aware that your XHTML templates are this way publicly accessible, which violates the recommendation in http://stackoverflow.com/questions/9031811/which-xhtml-files-do-i-need-to-put-in-web-inf-and-which-not You'd better move them outside the `/WEB-INF/resources` folder. Or, better, stick to JSF's own recommendation of `/resources` location for public webapp resources. – BalusC Aug 24 '14 at 09:15
  • @BalusC, thanks for the link, much appreciated. In regards to your comment regarding security concern, I am well aware of this and I have read your answer in the post you have provided. I have declared this security constraint in my `web.xml`, so I believe that everything is good now. – Maff Aug 24 '14 at 09:21