We use the @ManagedBean annotation to register a java bean using the JSF framework. This is a replacement for the faces-config.xml <managed-bean> element. Usually we do not use the name attribute, because by default it uses a simple class name with a camel.
We use @RequestScope and other area annotations to explicitly specify the area we want with the annotation. This is equivalent to specifying a <managed-bean-scope> xml entry. If you do not specify a scope, then by default will be @NoneScoped .
We use @ManagedProperty and specify an EL expression in its value attribute to use the JSF-provided dependency injection mechanism for JSF artifacts, such as other managed beans, with wider scopes and EL-defined variables such as param . We do this if we need entered values ββin other JSF artifacts, most typically beans. Injection values ββare available in the bean @PostConstruct -nomen method. This is an alternative to writing <managed-property> xml.
Summarizing. Use @ManagedBean @RequestScoped to register beans using the JSF framework. Use @ManagedProperty inside this bean to be able to reference among other other JSF beans with the same or wider areas in this bean. If you do not need to reference other beans in the created bean, you do not need to use the @ManagedProperty annotation, since it is optional.
source share