A quick cheat sheet:
Scope | JSF | CDI | Notes |
---|---|---|---|
Request | yes | yes | Ends after response. |
View | yes | no | Ends when user navigates “away”. |
Session | yes | yes | Available until session timeout or invalidation. |
Application | yes | yes | Available until web application is stopped. |
Conversation | no | yes | Controlled by conversation.begin() and conversation.end() . |
JSF @ManagedBean
- in javax.faces.bean
EE6 @ManagedBean
- in javax.annotation
(not part of JSF)
CDI beans use @Named
in javax.inject
for injection. JSF supports rudimentary injection using @ManagedProperty
- may be sufficient for your needs, though!
CDI scopes are in javax.enterprise.context
Ajax works well with view-scoped beans (JSF only), but not with request-scoped beans - because the scope does not persist beyond the response phase.