Reputation:
We have faces-config.xml
in JSF 1.0 where we entry about managed-beans, dependencies & navigations etc.
I was developing a sample project using JSF 2.0. But, as I don't know annotation, I need to include face-config.xml
externally. Please, provide the solution for it, as in JSF 2.0 we don't need to include it. What is reason behind it? How do we set a bean as managed-bean. What is annotation? How is it used?
Upvotes: 0
Views: 1442
Reputation: 1
You can employ a faces-config.xml in JSF2 exactly the same way you did in JSF 1.x. In fact, although annotations can often be used in place of a faces-config.xml file, not every JSF feature is available strictly through annotations, so sometimes you need a faces-config file even in JSF2.
There is one small difference, however, and that is that you should update the xml schema version reference in your faces-config file to reflect schema changes that came into effect with JSF2.
Upvotes: 0
Reputation: 570615
(...) 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.)
Upvotes: 2
Reputation: 597402
See the annotations tutorial.
For JSF, you can do something like this (using the @ManagedBean
annotation):
@ManagedBean
public class YourManagedBean {
...
}
Upvotes: 1