Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

faces-config.xml is config file

By default when we create a web application faces-config.xml doesnt created automatically. We must create him manually and as I understood faces-config.xml must be located strictly in WEB-INF.

So, my question:

Do I have to register faces-config.xml in web.xml after creation in WEB-INF or other folder or is it registered automatically. I.e. does JSF "know" what is the faces-config.xml and can find him in all project's folder.

Hope, I asked correct question.;)

like image 206
St.Antario Avatar asked Dec 07 '13 11:12

St.Antario


People also ask

Is xml a config file?

XML configuration files are text files that store mapping information for XML data types. The DSA reads the configuration files at startup and uses the information during run time to locate the DTD or XSD file and data source for each XML document.

Where do I put faces-config xml?

xml file is found in the META-INF directory of a jar in the application's classpath. A filename ending in . faces-config. xml is found in the META-INF directory of a jar in the application's classpath.

What is faces-config xml in JSF?

Each JSF application needs a faces-config. xml configuration file. It describes the application properties, such as navigation rules between the JSF pages, default bean instances, default values of some variables, message bundles, and so on.

Why config files are xml?

The primary motivation for using XML-based configuration is to be able to configure different instances of the same object in different ways. For example, with a single XML configuration file, you can specify different options for different applications.


1 Answers

As taken from FacesServlet documentation:

This servlet must automatically be mapped if it is not explicitly mapped in web.xml or web-fragment.xml and one or more of the following conditions are true.

  • A faces-config.xml file is found in WEB-INF.

  • A faces-config.xml file is found in the META-INF directory of a jar in the application's classpath.

  • A filename ending in .faces-config.xml is found in the META-INF directory of a jar in the application's classpath.

  • The javax.faces.CONFIG_FILES context param is declared in web.xml or web-fragment.xml.

  • The Set of classes passed to the onStartup() method of the ServletContainerInitializer implementation is not empty.

You can put your configuration file elsewhere in your webapp, but you need to keep in mind the following facts:

  1. You don't want to expose the file to be accessible, thus you'd want it to end up under WEB-INF/META-INF folders;
  2. You need to add the following entry to your web.xml:

    <context-param>
        <param-name>javax.faces.CONFIG_FILES</param-name>
        <param-value>
            WEB-INF/path/to/faces-config.xml
       </param-value>
    </context-param>
    

Otherwise the faces-config.xml is loaded automatically if found in some predefined locations.

like image 61
skuntsel Avatar answered Sep 23 '22 11:09

skuntsel