Bob Laing - April 19 2013 10:00:00 AMTweet
I attended Connect 2013 a few months ago and the first session I sat in on was Russ Maher's Jumpstart: JMP402 Master Class: Managed Beans and XPages: Your Time is Now. Excellent session. And I'll acknowledge up front and probably a few more times that I used code from Russ' sample database in this blog post.
One of the messages in Russ' Jumpstart session was that Managed Beans provide several benefits in an XPages application (performance is one) and Java is the direction that IBM is heading with Domino/XPages so no better time than now to start writing Managed Beans.
With the post Connect/Lotusphere buzz still ringing in my head, once I got back to the real world of work I decided to try to build a Managed Bean into one of the applications that I'm currently working on. As I've blogged about before (http://www.teamspace.ca/TeamSpace/Blog.nsf/dx/populate-xpage-combobox-choices-from-notes-multi-value-field.htm), one of the common actions that I use in many databases is to grab a value from a configuration document and populate some type of control such as a combobox or listbox. The blog post I made previously used SSJS to accomplish that, which works well and is relatively portable in that it can be plugged into other databases without much (or any) tweaking of code. So I set out to recreate that same functionality in a Managed Bean - and I was successful, however upon doing some further reading on Managed Beans now I wonder if I've actually created a bean, but more on that in a bit.
As I mentioned previously, Russ Maher provided excellent sample code with his Connect 2013 session and I used his SystemUtils bean verbatim. It worked as it was supposed to and provided a jumpstart for me. The slides from Russ' session can be found here: http://www.slideshare.net/RussellMaher/jmp402 and the sample code and database can be found here: http://www.rgmconsulting.com/TheCode. Both the slides and sample code are provided with Russ' permission.
I started by loading Russ' SystemUtils bean into the database. To accomplish this, from Designer under Code and then Java I clicked New Java Class and received this dialog box:
I entered com.teamspace.ca for the Package and SystemUtils for the name. The package is used to group Java classes and should be all lowercase. You should put whatever is appropriate as a package name, although you can use com.teamspace.ca if you wish. The name will be the name of the Java Class and should be descriptive of what the bundle of code does and also start with an uppercase letter. Clicking finish will present an empty Java Class. From this point I copied the contents of Russ's SystemUtils bean into the empty shell I just created and then saved.
The next step to make this bean available to the the application is to update the faces-config.xml file. This file is found under Package Explorer, the WebContent folder and then the WEB-INF folder as in the following screen shot:
Edit this file by double-clicking on it, and I added the following lines to the file:
Save and close this file and that's all that I did to get Russ's SystemUtils bean to work. This bean contains numerous utility classes to get objects such as the current database, a document given UNID, or a NotesSession. There is nothing specific to the application in this bean, but many classes that return common objects that any Domino developer will use when building an application.
Check back Monday for part 2 in this blog post where I post code that will look up and return a value from a document that is not a data source on the XPage.
- Comments