Over a million developers have joined DZone.

Declaring managed beans in JSF 2.0

· Java Zone

Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code! Brought to you in partnership with ZeroTurnaround.

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:

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

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

@ManagedBean(name=”CustomName”)
public class MyBean ..

From http://e-blog-java.blogspot.com/2011/06/declaring-managed-beans-in-jsf-20.html

The Java Zone is brought to you in partnership with ZeroTurnaround. Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code!

Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}