What Is New in JSF 2.2
JSF 2.2 brought a set of focused enhancements that modernized the framework for richer web applications. The update prioritized HTML5 friendliness, resource handling, and component development. These changes made it easier to integrate with modern front-end practices.
| Category | Key Changes |
|---|---|
| HTML5 Support | Passthrough Attributes, Passthrough Elements, Resource Library Contracts |
| Component Features | Stateless Views, f:ajax disabled attribute, Bean Validation integration |
| Resource Handling | Resource Library Contracts for themes, Resource packaging conventions |
| API Improvements | New ViewDeclarationLanguage methods, FacesFlow (early concept) |
How did JSF 2.2 improve HTML5 compatibility?
This was a major focus, introducing features to seamlessly work with HTML5. The passthrough attributes feature lets you render custom HTML5 data attributes directly onto JSF components. Passthrough elements allow you to use plain HTML5 tags that are treated as JSF components when needed.
In practice, you can now write code like this, mixing JSF and HTML5 naturally:
<h:inputText value="#{bean.value}">
<f:passThroughAttribute name="data-role" value="input" />
<f:passThroughAttribute name="placeholder" value="Enter text..." />
</h:inputText>
This matters because it bridges the gap between JSF's component model and the flexibility demanded by modern HTML5 and JavaScript frameworks.
What are the key new features for component authors?
JSF 2.2 added several powerful tools for building components. Stateless views, enabled by the transient attribute on the f:view tag, can significantly reduce memory overhead by not saving state. The f:ajax tag gained a disabled attribute for conditionally disabling Ajax behavior.
Bean Validation integration became more seamless, allowing validation groups to be specified directly on components. The ViewDeclarationLanguage API was expanded with methods like getComponentMetadata() and getScriptComponentResource(), giving component authors more control over the rendering pipeline.
How did resource handling get better?
Resource Library Contracts were introduced to finally solve the problem of theming and skinning. This feature allows you to package a complete set of resources -- CSS, images, JavaScript, and Facelets templates -- into a JAR file. The application can then switch between these packaged themes effortlessly.
This is a game-changer for large applications and teams that need to maintain multiple visual styles. It promotes reusability and clean separation between the core application logic and its visual presentation, moving beyond the limitations of the old resource library concept.
FAQ
What exactly are passthrough attributes and when should I use them?
Passthrough attributes allow you to add arbitrary HTML5 attributes (like data-*, placeholder, or type) to standard JSF components. Use them whenever you need to enhance a component with HTML5 features or integrate with JavaScript libraries without writing a custom renderer.
Does Stateless View mode mean my entire application becomes stateless?
No. It's a per-view setting. When you set transient="true" on f:view, that specific page won't save its UI component state. This is great for simple, read-heavy pages but not for forms with complex state. Your application can mix stateful and stateless views.
How do Resource Library Contracts improve on regular resources?
Regular resources are just individual files. A Contract is a packaged, self-contained theme. It can include templates, composite components, images, CSS, and JS all together in a JAR. This makes themes into reusable, versionable artifacts you can deploy independently from your application.
Is FacesFlow production-ready in JSF 2.2?
Not really. JSF 2.2 included an early, foundational API for FacesFlow (like the @FlowScoped annotation), but it was not fully realized. The complete and usable flow feature came later in JSF 2.2. Think of the 2.2 implementation as a precursor.
Can I use the new HTML5 features with older JSF components?
Yes, absolutely. The passthrough features are designed to work with existing standard and custom components. You can augment a legacy h:inputText with HTML5 attributes without modifying the component itself, which is great for gradual modernization of older applications.