Does JSF encounter a configuration file outside of WEB-INF?

When creating configuration files with multiple faces, is it correct to have faces-config.xml outside WEB-INF? The JSF specification does not seem to be very clear (section 10.1.3)

If so, how should this faces-config.xml file be declared in web.xml? paths created by the IDE (e.g. Eclipse / JDev) usually 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 face-config.xml is outside WEB-INF - is it correct to declare the parameter value as "/WebContent/WEB-INF/faces-config2.xml"?

+6
java jsf web-inf faces-config
source share
3 answers

Perhaps, but not recommended. The reason you host the configuration files in WEB-INF is because the server cannot serve these files — you have your own code, database configuration, and other important things.

You cannot use "/WebContent/WEB-INF/faces-config2.xml" - AFAIK "WebContent" is eclipse-specific. have configuration file names that must be absolute inside the WAR. This means that they always begin with "/ WEB-INF /".

+7
source share

As mentioned in David's answer, it is not recommended to place configuration files outside the WEB-INF directory. However, if you are looking for ways to organize your project, you can try creating a new subdirectory under WEB-INF.

For example, when I deal with a lot of faces configuration files, I will create the /WEB-INF/config and place the config files there.

+1
source share

If you link to them from web.xml, then the file must be at war at runtime. There are other ways that a container can detect faces-config.xml resources.

10.4.2 During application launch, before processing any requests, the JSF implementation must process zero or more application configuration resources located in accordance with the following Algorithm:

  • Find all the resources with the name "META-INF / faces-config.xml" in the ServletContext Resource Resources for this web application and load them as JSF (in the reverse order in which they getResources () for the current ContextClassLoader streams).

  • Check for a context initialization parameter named javax.faces.CONFIG_FILES. If it exists, consider it as a comma-delimited list of contextual paths of relative resources (starting with "/") and load each of the specified resources.

  • Check for a web application configuration resource with the name "/ WEBINF / faces-config.xml" and load it if the resource exists.

0
source share

All Articles