Because I am constantly busy working on something, I have never had time to actually put everything in words and pictures. But, since you got here, then you must have already seen some part of my work - and this is the way I’m talking.I'm 23, born in Romania, student at UPG Romania in software development field. I started from 0, mostly with basic stuff, and I’m evolving every day to an expert. I'm focused on freelancing projects, from small websites, to really heavy stuff. I know that I look and act differently from most developers, but this is why you will love to work with me! Constantin has posted 42 posts at DZone. You can read more from them at their website. View Full User Profile

Declaring managed beans in JSF 2.0

  • submit to reddit

In the next example we will see how to declare a managed bean in JSF 2.0. There are two ways to configure the managed bean :

1. Declaring a Managed Bean in faces-config.xml descriptor file as below:

    <description>description of the managed bean</description>
    <managed-bean-name>name of the managed bean</managed-bean-name>
    <managed-bean-class>fully qualified class name</managed-bean-class>
    <managed-bean-scope>scope of the bean</managed-bean-scope>
        <property-name>name of the bean property</property-name>
        <value>Default value of the property</value>
2. In JSF 2.0, you can annotated a Java class with @ManagedBean annotation to turn it into a Managed Bean:
public class MyBean ...

In addition, you can customize the bean name, by adding the name clause to the annotation:

public class MyBean ..


Published at DZone with permission of its author, Constantin Alin.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)



Juergen Zimmermann replied on Fri, 2011/07/01 - 12:01am

You've forgotten to mention Managed Beans by CDI which provides much more options than the JSF based Managed Beans.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.