What Is New in JSF 4.0
JSF 4.0 is a major release focused on modernization, aligning with Jakarta EE 9+ and removing legacy cruft. It streamlines development with new CDI-centric features and drops support for older technologies.
| Category | Key Changes |
|---|---|
| New Features | New CDI-based @ApplicationScoped annotation, faces-flow scope, Page Flow in XML. |
| Improvements | Full alignment with Jakarta EE 9+ namespace (jakarta.*), enhanced error handling. |
| Removed & Deprecated | Removed JSF 1.x/2.0 legacy features, deprecated the javax.faces.bean package. |
How did the package namespace change in JSF 4.0?
The most visible change is the move from javax.faces to jakarta.faces. This aligns JSF with the broader Jakarta EE 9+ platform, which underwent this rename. You'll need to update all your imports and configuration files to use the new namespace.
In practice, this means your old imports like import javax.faces.context.FacesContext; must become import jakarta.faces.context.FacesContext;. Your web.xml and faces-config.xml also need to reference the new schema locations.
What new scopes were introduced?
JSF 4.0 introduces a new CDI-based @ApplicationScoped annotation to replace the old JSF-specific one. This reinforces the shift towards using CDI for all dependency injection and scoping, making your code more consistent with modern Jakarta EE standards.
The release also formalizes the faces-flow scope. This scope is now properly defined for use within a Faces Flow, providing a cleaner way to manage bean lifecycles that are specific to a navigation flow.
What was removed or deprecated?
A significant amount of legacy baggage was removed. This includes all the old JSF 1.x and 2.0 legacy features that were previously kept for backward compatibility. The framework is now leaner and focused on modern development practices.
The entire javax.faces.bean package, which housed the old @ManagedBean, @RequestScoped (JSF), and other annotations, is now officially deprecated. You should have already migrated to CDI's jakarta.enterprise.context package, but this makes it clear that the old way is on its way out.
How does JSF 4.0 improve Faces Flows?
Faces Flows now support being defined in XML files. This allows you to configure your page flows declaratively alongside your managed beans and navigation rules, offering more flexibility compared to defining everything in Java code.
This is useful for creating self-contained modules or wizards where you want the flow logic to be externalized and easily configurable without recompiling Java classes.
Were there any changes to error handling?
Yes, the error handling mechanism was improved. The specification now provides more detailed requirements for how implementations should handle and report errors, leading to better and more consistent debugging information during development.
This matters because it helps developers pinpoint issues faster, especially in complex applications where the root cause of a Faces exception might be buried deep in the component tree or lifecycle.
FAQ
Is JSF 4.0 backwards compatible with my JSF 2.x applications?
Not directly. The change from javax.* to jakarta.* namespace is a breaking change. You will need to update all your imports, Maven dependencies, and XML schemas. Legacy features from JSF 1.x/2.0 have also been removed.
Do I have to use CDI with JSF 4.0?
Practically, yes. The old javax.faces.bean managed bean system is deprecated and scheduled for removal. JSF 4.0 is designed around CDI, so using CDI for dependency injection and scoping is the standard and recommended approach.
What is the new @ApplicationScoped annotation?
It's a CDI-based replacement for the old JSF-specific @ApplicationScoped annotation. You should now import it from jakarta.enterprise.context instead of javax.faces.bean to ensure proper integration with the CDI container.
Can I still use Facelets as the view technology?
Absolutely. Facelets remains the primary and default view declaration language for JSF 4.0. There have been no announcements about replacing it.
Where can I find the full list of changes?
The official Jakarta Faces 4.0 release notes and specification document are the definitive sources. The GitHub release page also provides a high-level overview of the major changes and links to the relevant commits.