(...) in JSF 2.0 we don't need to include it. What is reason behind it?
In three words: ease of development. There is just less code to write -- boilerplate code is removed, defaults are used whenever possible, and annotations are used to reduce the need for deployment descriptors.
How do we set a bean as managed-bean. What is annotation? How is it used?
Managed beans are identified using the @ManagedBean
annotation. The scope of the bean is also specified using annotations (@RequestScoped
, @SessionScoped
, @ApplicationScoped
, etc).
So the following in JSF 1.0:
<managed-bean>
<managed-bean-name>foo</managed-bean-name>
<managed-bean-class>com.foo.Foo</managed-bean-class>
<managed-bean-scope>session</managed-bean>
</managed-bean>
Can be rewritten as such in JSF 2.0:
@ManagedBean
@SessionScoped
public class Foo {
//...
}
And referred like this in a Facelet page:
<h:inputText label="eMailID" id="emailId"
value="#{foo.email}" size="20" required="true"/>
(By default, the name of the managed bean will be the name of the annotated class, with the first letter of the class in lowercase.)
See also