What Is New in JSF 2.0
JSF 2.0 was a major overhaul focused on developer productivity and modern web application features. It introduced annotations, Ajax integration, and a component-based development model that significantly reduced boilerplate code.
| Category | Key Changes |
|---|---|
| New Features | Facelets as default view handler, Standard Ajax support, Composite Components, Resource Handling |
| Annotations | Dependency Injection with @ManagedBean, @ManagedProperty, Scoping with @RequestScoped, @ViewScoped |
| System Events | New event model for lifecycle phase, component, and application events |
| Navigation | Implicit navigation based on outcome, Conditional navigation |
| Validation & Conversion | Bean Validation (JSR-303) integration |
How did JSF 2.0 simplify backing bean management?
JSF 2.0 eliminated the need for verbose faces-config.xml declarations through annotations. You can now define a managed bean and its scope directly in the Java class.
This approach is much faster and keeps the configuration tightly coupled with the code it affects. In practice, it made creating and managing the model layer of a JSF application feel more natural and less XML-heavy.
Example with Annotations
@ManagedBean
@RequestScoped
public class UserBean {
@ManagedProperty(value="#{param.id}")
private String userId;
// ... getters and setters
}
What Ajax capabilities were added to JSF 2.0?
JSF 2.0 built Ajax right into the core framework with the <f:ajax> tag. This allowed you to add partial page rendering and asynchronous behavior to any component without external libraries.
You could easily specify which components to execute and which to render after an Ajax event. This was a game-changer for creating dynamic, desktop-like user experiences without complicated JavaScript integration.
Basic Ajax Example
<h:inputText value="#{bean.value}">
<f:ajax event="keyup" render="output" />
</h:inputText>
<h:outputText id="output" value="#{bean.value}" />
Why was Facelets made the default view technology?
Facelets replaced JSP as the recommended and default view handler because it was designed specifically for JSF's component tree model. It offered a more natural templating system, better error reporting, and higher performance.
Features like composite components and decorating entire pages became possible because of Facelets. This shift resolved many of the compatibility and lifecycle conflicts that existed when using JSP with JSF 1.x.
How did resource handling improve in JSF 2.0?
The framework introduced a standard way to manage CSS, JavaScript, and images through the Resource API and the <h:outputScript> and <h:outputStylesheet> tags.
You could now place resources in a dedicated /resources directory and reference them easily. The framework also handles versioning and packaging, which simplifies deployment and caching.
Resource Directory Structure
WebContent
|-- resources
|-- css
|-- style.css
|-- js
|-- script.js
|-- images
|-- logo.png
FAQ
Do I have to use Facelets in JSF 2.0, or can I still use JSP?
While JSP is still supported for backward compatibility, Facelets is the default and recommended view technology. New projects should absolutely use Facelets for its superior performance, templating, and component support.
Can I use JSF 2.0 Ajax alongside a third-party library like RichFaces?
Yes, the standard <f:ajax> component is designed to work alongside component library Ajax features. However, you might choose one approach for consistency within a project.
What is the difference between @ManagedBean and @Named?@ManagedBean is the JSF-specific annotation. @Named is part of CDI (Contexts and Dependency Injection). In JSF 2.0, @ManagedBean is the standard, but CDI integration becomes more prominent in later versions.
How do composite components reduce development time?
They allow you to create new components from existing ones using only XHTML, without writing any Java code. This lets teams build a library of reusable UI widgets specific to their application's needs.
Does implicit navigation work with conditional outcomes?
Yes, you can return a String outcome from an action method, and JSF will automatically navigate to the page with that name. For conditions, you can use the <h:link> or <h:button> outcome attribute.