JBoss.orgCommunity Documentation

Chapter 5. Managed Beans

5.1. Code Generation for Managed Beans
5.2. Add Existing Java Beans to a JSF Configuration File

There is lots of power to work with managed beans.

Thus, in this section we will guides you through all this possibilities.

To start, create a new managed bean in JSF configuration file editor, in the Tree view.


Note:

When you define a new managed bean, make sure that Generate Source Code is checked as shown in the figure below.


After the "Java" class has been generated you can open it for additional editing. There are two ways to open the "Java" class:

  • click on Managed-Bean-Class link in the editor

or

  • right click the managed bean and select Open Source


The generated Java source should look as follows:


You can also generate source code for properties, also includes "getter" and "setter" methods. Right click on the bean and select New > Property . You will see Add Property dialog.


When the form is open make sure that all the check boxes are selected:

  • Add Java property

  • Generate Getter

  • Generate Setter


Once the generation is complete, you can open the file and see the added property with "get" and "set" methods:


Thus, we've discussed everything which comes to creating a new Managed Bean. The next section will show you how to add an existing Bean into a JSF configuration file.

If you already have a Java bean you can easily add it to a JSF configuration file.

You should start the same way you create a new managed bean. Use the Browse... button to add your existing Java class.


Once the class is set, its Name will be set as well. But you can easily substitute it for the other one. Notice that Generate Source Code option is not available as the "Java" class already exists.

After adding your class Next button will be activated. Pressing it you'll get Managed Properties dialog where all corresponding properties are displayed. Check the necessary ones to add them into your JSF Configuration File.


If you don't want to add any, just click Finish.

Above-listed steps have demonstrated how you can specify an existing Bean in the JSF configuration file, i.e. faces-config.xml. In the next chapter you'll know how to organize and register another kind of artifacts.