четверг, 19 апреля 2012 г.

Understanding JSF - Part 3 - Bean scope

This post is a continuation of JSF tutorials series. If you are new to jsf I would recommend you to read the previous jsf tutorials. In this session I will explain bean scopes in jsf. When you are developing an application you have a variety of components, each for a different task. In order to make those components work as they have to we have scopes. We can define 3 scopes for JSF and CDI beans:

1. Request scope
2. Session scope
3. Application scope

In JSF 2 we also have View scope and Conversation scope. 

In order to assign a scope for your bean you would use the following annotations during declaration:
@RequestScope
@SessionScope
@ApplicationScope

Session scope


If the Session scope is declared your bean will be held until the session is over. This type of scope is usually used in order to store user data during the session, or for example in a web store you would use session scope in order to store the items in the shopping cart.

Request scope


Request scope is the most common scope. You would use it practically in every action like saving information to the database, retrieving it, deleting it and so on. 

Application scope


Application scope indicates that the information of the bean will be stored starting from the moment the application has been launched and until it is stopped. 

Best regards,
Netlink community member

Комментариев нет:

Отправить комментарий