Quantcast
Channel: None – Dec's Dom Blog
Viewing all articles
Browse latest Browse all 30

Getting To The Java Roots of XPages – Part 7

$
0
0

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 WebContent\WEB-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

<?xml version="1.0" encoding="UTF-8"?>
<faces-config>
  <managed-bean>
    <managed-bean-name>myManagedBean</managed-bean-name>
    <managed-bean-class>scary.java.demo.AboutMe</managed-bean-class>
    <managed-bean-scope>view</managed-bean-scope>
  </managed-bean>
  <!--AUTOGEN-START-BUILDER: Automatically generated by IBM Domino Designer. Do not modify.-->
  <!--AUTOGEN-END-BUILDER: End of automatically generated section-->
</faces-config>

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

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
	This is an example of a managed bean
	<xp:br />
	<xp:br />
	<xp:link escape="true" text="#{myManagedBean.myInternetAddress}" id="link1" value="/myPage.xsp" />
</xp:view>

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.


Viewing all articles
Browse latest Browse all 30

Trending Articles