Bean Scopes:
None:
Request:
View:
Session:
Application:
Example:
Step 01: Create Managed Bean.
Step 02: Create XHTML Page.
Step 03: Output
None:
- Objects with this scope are not visible in any JSF page.
- When used in the configuration file, they indicate managed beans that are used by other managed beans in the application.
- Objects with none scope can use other objects with none scope.
- Exa. @NoneScoped
Request:
- Objects with this scope are visible from the start of the request until the end of the request.
- Request scope starts at the beginning of a request and ends when the response has been sent to the client.
- If the request is forwarded, the objects are visible in the forwarded page, because that page is still part of the same request/response cycle.
- Objects with request scope can use other objects with none, request, session, or application scope.
- Exa. @RequestScoped
View:
- Bean lives as long as the user is interacting with the same JSF view in the browser window/tab.
- It gets created upon an HTTP request and gets destroyed once the user postbacks to a different view.
- Exa. @ViewScoped
Session:
- An object with session scope is visible for any request/response cycle that belongs to a session.
- Objects with this scope have their state persisted between requests and last until the object or the session is invalidated.
- Objects with session scope can use other objects with none, session, or application scope.
- Exa. @SessionScoped
Application:
- An object with application scope is visible in all request/response cycles for all clients using the application, for as long as the application is active.
- Objects with application scope can use other objects with none or application scope.
- Exa. @ApplicationScoped
Example:
Step 01: Create Managed Bean.
Step 02: Create XHTML Page.
Step 03: Output
Tags:
Java