Create managed bean
To create a manage bean you need the annotation @ManagedBean
for example:
@ManagedBean
public class Example {}
You need the package:
import javax.faces.bean.ManagedBean;
Managed bean Scope
We use annotations to define the scope in which the bean will be stored.
There are many scope of managed bean: @NoneScoped, @RequestScoped, @ViewScoped, @SessionScoped, @ApplicationScoped
, ...
@ApplicationScoped
): Application scope persists across
all users’ interactions with a web application.@SessionScoped
): Session scope persists across multiple HTTP
requests in a web application.@ViewScoped
): View scope persists during a user’s interaction
with a single page (view) of a web application.@RequestScoped
): Request scope persists during a single HTTP
request in a web application.@NoneScoped
): Indicates a scope is not defined for the
application.@CustomScoped
): A user-defined, nonstandard scope. Its value
must be configured as a java.util.Map
. Custom scopes are used
infrequently.