From the following figure, you can seek some guidance for dealing with some of the most popular cases:
As a general rule in JSF, don't use objects that have shorter lifespan than the objects you are calling it from. In other words, use objects whose lifespan is the same as, or longer than, the object being injected into. Breaking this rule will end up in a JSF exception.
Common mistakes (bad practices):
- Use request objects in session objects
- Use session objects in application objects
Nevertheless, for CDI, these cases are not such a big issue. When you are using an object that has a shorter lifespan than the object you are calling it from (for example, injecting a request scoped bean into a session scoped bean), CDI classifies the use case as a mismatched injection and fixes the issue via CDI proxies. For each request, the CDI proxy re-establishes the connection to a live instance of the request scoped bean.
Keep in mind also:
- Overusing a view scoped bean for request scoped data may affect memory.
- Overusing a request scoped bean for view scoped data may cause forms with unexpected behavior.
- Overusing an application scoped bean for request/view/session scoped data may cause an undesirably wide visibility of data across users and will affect memory.
- Overusing a session scoped bean for request/view data may cause an undesirably wide visibility of data across multiple browser windows/tabs in that session.
Starting with JSF 2.0, managed beans can be injected (dependency injection) into the property of another managed bean using the @ManagedProperty annotation. Another way to inject beans is to use the @Inject annotation, which is part of the CDI powerful injection mechanism.
Read more:
JSF 2.2, CDI and OmniFaces Scopes List
|
|
|
Search on blog
Petition by Java EE Guardians
Abonați-vă la:
Postare comentarii
(
Atom
)
|
| [JSF Page Author Beginner's Guide] |
Postări populare
OmniFaces/JSF Fans
-
▼
2015
(
516
)
- ► septembrie ( 38 )
-
▼
iulie
(
25
)
- JavaServer Faces books collection
- JSF and Singleton design pattern
- Java EE 8 comes with Ozark
- JSF and EJBs Facade design pattern sample
- Indeterminate checkboxes with JSF and OmniFaces
- [JSF Page Author Beginner's Guide] JSF <selectBool...
- Web Development with Java and JSF by Michael Müller
- HTTP 2.0 Comes to Java: What Servlet 4.0 Means to You
- Some JSF news By David Delabassee
- Use OmniFaces Tree to render JSON
- OmniFaces approach for writing custom ELContexts
- OmniFaces approach for writing custom ELResolvers
- [OmniFaces utilities 2.2] Refresh the current page...
- JSF 2.3 new feature: registrable DataModels
- [OmniFaces utilities 2.2] Refresh the current page...
- Introducing the OmniFaces Runner Scope
- Inject CDI in JSF and vice versa
- JSF/CDI Bean Injection Short Overview
- JSF 2.2, CDI and OmniFaces Scopes List
- [OmniFaces utilities 2.2] Update the row of the gi...
- OmniFaces 2.1 - Inject HTTP cookie via @Cookie ann...
- OmniFaces Utilities ZEEF Page
- OmniFaces 2.1 - ReadOnlyValueExpression that can b...
- [OmniFaces utilities 2.1] Get the value of the giv...
- [OmniFaces utilities 2.1] Get a string for the giv...
JSF/OmniFaces Resources |







JSF 2 Tutorials at www.mkyong.com
JavaServer Faces (JSF) Tutorial 

















Niciun comentariu :
Trimiteți un comentariu