Java Reference
In-Depth Information
Dependent scope and CDI
A common CDI mistake is to use a bean with the dependent scope as a backing bean for a
JSF page. The problem with this approach is that each invocation will result in a new bean
being created. When the user then submits the form, a new instance will be created, and
it will appear as if the user never entered anything and the validation rules were skipped.
Always use at least @RequestScoped or the stereotype @Model .
When using CDI, each bean is associated with a scope. The scope determines the lifecycle
of the bean.
Conversation scope
The conversation scope deserves its own section. Unlike the other scopes, the conversation
scope is a completely new beast. If you've used the forerunner to CDI, JBoss Seam (ver-
sions 1 or 2), you're probably familiar with the concept of a conversation. A conversation
is a scope that's shorter than a session but longer than a request. This is shown in figure
12.2 . A conversation is controlled programmatically; code determines when a conversation
begins and ends.
Search WWH ::




Custom Search