2.1.5.1. Code Generation for Managed Beans

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

Creation of New Managed Bean

Figure 2.36. Creation of New Managed Bean


Note:

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

New Managed Bean

Figure 2.37. New Managed Bean


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

Opening of Created Managed Bean

Figure 2.38. Opening of Created Managed Bean


The generated Java source:

Java Source Code

Figure 2.39. Java Source Code


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.

Generation of Source Code for Properties

Figure 2.40. Generation of Source Code for Properties


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

  • Add Java property
  • Generate Getter
  • Generate Setter

"Add Property" Form

Figure 2.41. "Add Property" Form


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

Generated Java Source Code for Property

Figure 2.42. Generated Java Source Code for Property


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