Java EE 8 Application Development
上QQ阅读APP看书,第一时间看更新

Optional faces-config.xml

Legacy J2EE applications suffered from what some have considered to be excessive XML configuration.

Java EE 5 took some measures to reduce XML configuration considerably. Java EE 6 reduced the required configuration even further, making the JSF configuration file, faces-config.xml, optional in JSF 2.0.

In JSF 2.0 and newer versions, JSF managed beans can be configured via the @ManagedBean annotation, obviating the need to configure them in faces-config.xml. Java EE 6 introduced the Contexts and Dependency Injection (CDI) API, which provides an alternate way of implementing functionality typically implemented with JSF managed beans. As of JSF 2.2, CDI named beans are preferred over JSF managed beans; JSF 2.3 went even further, deprecating specific JSF-managed beans in favor of CDI named beans.

Additionally, there is a convention for JSF navigation: if the value of the action attribute of a JSF 2.0 command link or command button matches the name of a facelet (minus the XHTML extension), then by convention, the application will navigate to the facelet matching the action name. This convention allows us to avoid having to configure application navigation in faces-config.xml.

For many modern JSF applications, faces-config.xml is completely unnecessary as long as we follow established JSF conventions.