The faces-config.xml file is the optional application configuration file of Jakarta Faces (formerly JavaServer Faces, JSF). It declares things the framework cannot infer from annotations, such as explicit navigation rules, resource bundles, supported locales, phase listeners, custom factories and flows. It lives in WEB-INF/faces-config.xml.
Since JSF 2.0 the file is no longer required. Managed beans, converters, validators and renderers are registered with annotations, and navigation can be implicit. Modern Faces applications keep a short faces-config.xml or none at all.
faces-config.xml is forfaces-config.xml is forThe Faces runtime reads configuration from several places and merges them: annotations on classes, WEB-INF/faces-config.xml, and META-INF/faces-config.xml files inside library JARs. The XML file is the place for settings that have no annotation equivalent or that you want to change without recompiling.
| Concern | Today's approach |
|---|---|
| Backing beans | CDI annotations such as @Named and @RequestScoped |
| Converters and validators | @FacesConverter and @FacesValidator |
| Simple page navigation | Implicit navigation, returning a view name |
| Complex or centralised navigation | navigation-rule in faces-config.xml |
| Messages and i18n | resource-bundle and locale-config in faces-config.xml |
| Lifecycle hooks and factories | lifecycle, factory and application elements |
| Multi-page flows | Flow definitions, in XML or Java |
For Jakarta Faces 4.0 (part of Jakarta EE 10), the root element uses the Jakarta namespace.
Older applications use the http://java.sun.com/xml/ns/javaee or http://xmlns.jcp.org/xml/ns/javaee namespaces and javax.faces classes. Jakarta Faces 3.0 and later use jakarta.faces packages, so a migration to Jakarta EE 9 or newer must update both the namespace and the imports.
Explicit navigation maps a logical outcome from an action to a target page.
An action method such as String login() returning "success" or "failure" triggers these cases. The <redirect/> element sends an HTTP redirect, which prevents a repeated form submission when the user reloads the page.
Implicit navigation covers the simple cases without any XML. An action that returns "home" goes to home.xhtml, and "home?faces-redirect=true" redirects.
Registering beans in XML with <managed-bean> is obsolete. The JSF native managed bean facility, including @ManagedBean, was deprecated in JSF 2.3 and removed in Faces 4.0. Use CDI instead.
Converters and validators are registered with annotations:
You can still declare them in XML with <converter> and <validator> elements, which is useful when a library ships components without annotation scanning.
<application> holds resource-bundle, locale-config, message-bundle, action-listener and view-handler settings.<factory> replaces core factories, such as the exception-handler-factory, to customise global error handling.<lifecycle> registers a <phase-listener> to run code before or after a lifecycle phase.<ordering> and <absolute-ordering> control the load order when several faces-config.xml files exist in JARs.<flow-definition> defines flows with a start node, views, and return nodes, as an alternative to annotations.<protected-views> restricts which views can be reached only from within the application.The metadata-complete attribute set to true tells the container to skip annotation scanning, which can speed up startup on large deployments but requires every artefact to be declared in XML.
src/main/webapp/WEB-INF/faces-config.xml in a WAR project.version and schema for your Faces release: 4.0 for Jakarta EE 10, 4.1 for Jakarta EE 11, and 3.0 for Jakarta EE 9.beans.xml or bean-discovery setup exists so that @Named beans are found.jakarta.faces.PROJECT_STAGE in web.xml to Development while developing to get helpful diagnostics.faces-config.xml mandatory?No. Since JSF 2.0 a Faces application runs without it, provided the FacesServlet is configured and beans are registered through annotations.
faces-config.xml go?In WEB-INF/ of the web application. Libraries put theirs in META-INF/ inside the JAR.
Not in Faces 4.0. Managed beans were removed, so use CDI beans. Older JSF 2.x applications may still use the XML or the @ManagedBean annotation.
Faces navigation is outcome based: an action returns a string and the runtime maps it to a view, whereas Spring MVC maps URLs to controllers directly.
faces-config.xml centralises the Faces settings that annotations do not cover: explicit navigation, localisation, factories, phase listeners and flows. It is optional in modern applications, which rely on CDI beans and annotated components. Use the right Jakarta namespace and version, and keep the file short.