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
-
If you like this article, I think you are going to like JSF 2.3 Tutorial as well.
-
Starting with JSF 2.3 the JSF "native" managed bean annotations are officially deprecated. So, there is no doubt now that CDI is ...
-
[OmniFaces utilities] The getRequestURL() method returns the HTTP request URL with query string, regardless of any forward. This is the f...
-
Let's checkout a common practice for declaring constants in Java using the public static final declaration: public class Circle { ...
-
[OmniFaces utilities] The getActionExpressionsAndListeners() method returns a list of all action expressions and listeners associated wit...
-
[OmniFaces utilities] The getCurrentActionSource() method returns the source of the currently invoked action, or null if there is none, ...
-
Before you read this post please read: Use a CDI alternative as a mock implementation for a stateless session bean So, since you are fa...
-
Starting with JSF 2.3, more exactly with m07 , we can take advantage of using the auto detection of convertors based on 1st UISelectMany it...
-
[OmniFaces utilities] The isSerializable() method returns true if the given object is serializable. Method: Usage: Example 1 - te...
-
[OmniFaces utilities] The reverseArray() function returns a copy of the array with items in reversed order. Function: Usage: Let...
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 |
Niciun comentariu :
Trimiteți un comentariu