JSF faces config file outside WEB-INF?
Asked Answered
S

3

6

When creating multiple faces config files, it is correct to have the faces-config.xml outside of WEB-INF? The JSF spec does not seem to be very clear about this (Section 10.1.3)

If yes, how should this faces-config.xml be declared in web.xml? the paths generated by IDE's (like Eclipse/JDev) generally use something like:

<context-param>
    <param-name>javax.faces.CONFIG_FILES</param-name>
    <param-value>/WEB-INF/faces-config1.xml</param-value>
</context-param>

Now, if my faces-config.xml is outside WEB-INF -- is it correct to declare the param-value as something like "/WebContent/WEB-INF/faces-config2.xml"?

Stork answered 2/9, 2009 at 1:51 Comment(0)
I
7

It is possible, but not recommended. The reason you put configuration files under WEB-INF is that the server knows not to serve these files - you have your code, database configuration and other sensitive stuff there.

You cannot use "/WebContent/WEB-INF/faces-config2.xml" - AFAIK "WebContent" is eclipse specific. have the config files names to be absolute inside the WAR. It means that they will always begin with "/WEB-INF/".

Inarch answered 2/9, 2009 at 12:27 Comment(0)
A
1

As mentioned in David's answer, it's not recommended to put the config files outside of the WEB-INF directory. However, if you're looking for ways to organise your project, you might try creating a new subdirectory under WEB-INF.

For example, when I'm dealing with lots of faces-config files, I'll create a directory /WEB-INF/config and put the faces-config files in there.

Armes answered 4/9, 2009 at 4:37 Comment(0)
O
0

If you are referencing them from the web.xml, then the file needs to be in the war at runtime. There are other ways that the container can discover faces-config.xml resources.

10.4.2 At application startup time, before any requests are processed, the JSF implementation must process zero or more application configuration resources, located according to the following algorithm:

  • Search for all resources named “META-INF/faces-config.xml” in the ServletContext resource paths for this web application, and load each as a JSF configuration resource (in reverse order of the order in which they are returned by getResources() on the current Thread’s ContextClassLoader).

  • Check for the existence of a context initialization parameter named javax.faces.CONFIG_FILES. If it exists, treat it as a comma-delimited list of context relative resource paths (starting with a “/”), and load each of the specfied resources.

  • Check for the existence of a web application configuration resource named “/WEBINF/ faces-config.xml”, and load it if the resource exists.

Odessaodetta answered 2/9, 2009 at 12:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.