I get many informations from this web sites:
Why annotations?
Generally we use annotation to facilitate the development and to make the code more clear and clean.
What are annotations?
Java 5 annotations provide standardization of metadata in a general goal. This metadata associated with Java features can be exploited in the compilation or execution.
Java was modified to allow the implementation of annotations:
Where can annotations be used?
Annotations can be used with :
packages, classes, interfaces, constructors, methods, fields, parameters, variables or annotations themselves.
Categories of annotation
There are three categories of annotation:
For example @Deprecated
, @Override
...
For example @MyAnnotation ( "test")
For example @MyAnnotation (arg1 = "test 3", arg2 = "test 2", arg3 = "test3")
Like we see before you can create your own annotation
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.