In the last part we setup our bean as an unmanaged bean by creating a DataContext and creating the bean in there. To make things even easier you can create what is known as a managed bean. Basically you setup the bean at an application level. You give it a name and scope and tell it what class it is using. Then at the page level you can just reference the bean in EL without having to do anything special.
The setup of the managed bean is done in a properties file called faces-config. In DDE 8.x you can access this file by using the package explorer and looking in the WebContentWEB-INF folder in the nsf. In DDE 9 there is an option in the preferences to show the file in the Application Configuration section of the nsf and I’d recommend that you enable the option.
I’ve added my managed bean as follows
myManagedBean scary.java.demo.AboutMe view
I only added the <managed-bean> section. The rest was already in the faces-config and whatever you do don’t remove or edit the lines starting with <!–AUTOGEN
Now that the managed bean is setup I can change my link to reference it by name. Here is the XML for the entire xpage I’m using for my demo
This is an example of a managed bean
When the XPage renderer first hits the Expression Language for myManagedbean it will call the empty constructor and then call the method getMyInternetAddress() to return a value.
So really a managed bean is just a way to pre-define the name and scope for a bean and a bean is just a java class with a few special bits for serialization.
This is not as scary as it seems any more but you have to admit, that java class I wrote is a bit useless so in the next few parts I’ll work on making it a little better and add a few extra methods.