Developing an OpenLaszlo App
Introduction
XML technology is in its high tide and companies are enthusiastic to leverage its power and flexibility. Presentation tier technology based on XML is also gaining momentum in this wave. Database vendors have been providing implicit support for XML in their DB products for quite some time. IBM offers XML support with DB2 Express-C software that is free in all aspects: free for development, production, and even distribution. OpenLaszlo has come up with an XML-based scripting framework that is worth notice due to its visual appeal, flexibility, and efficiency. The foundation block is XML and they form a buddy pair unlike any other.
In this article, we shall develop an addressbook application end-to-end using OpenLaszlo, DB2 and Java. The functionality is simple but should be able to demonstrate the integration of technologies discussed above. This is a sequel to Introducing OpenLaszlo, which provided a quick-start on setting up a development environment with Ant and IDE4Laszlo. We will build on this application using the development environment discussed therein.
Download the Required Software
The following software is required in addition to the development environment to try out the address book application:
-
Download and install DB2 Express-C. This is free for download, development, and production. You can learn more about IBM XML database there too.
-
Download the source code for the entire application.
Install Software
Install DB2 Express-C by following the instructions in the installation program.
Create the Database adbookdb:
- Since this is an XML database, the structure of the table is very simple with just two columns (see Figure 1).

Figure 1. The structure of the adbookdb. - Go to Windows Start >> Programs >> IBM DB2 >> and DB2 Command Editor. Alternatively, you can right-click the DB icon in the windows notification area and start(DB2) or launch Command Editor (see Figure 2).

Figure 2. The DB2 Community Edition quick launch - Run the scripts in the following listing to set up the database.
Listing 1.
CREATE DATABASE ADBOOKDB USING CODESET UTF-8 TERRITORY US~ CONNECT TO ADBOOKDB user db2admin using 'db2admin'~ CREATE SCHEMA DB2ADMIN AUTHORIZATION DB2ADMIN~ CREATE TABLE DB2ADMIN.ADDRESSBOOK (EMAILID CHARACTER (50) NOT NULL PRIMARY KEY, CONTACTINFO XML) ~The above file contains scripts that will insert 10 records into the database. A person's email ID is the primary key from which the subsequent XML string is inserted into the database. The entire contact information of the person goes as elements of a single XML string. The code below is an example of the insert script: note that to give a one-to-one correspondence to the XML and the primary key, the email ID is maintained as an attribute to the <person> element.
insert into db2admin.addressbook values ('grace.thomas@yahoo.com',' <person email="grace.thomas@yahoo.com"> <firstname>Grace</firstname> <lastname>Thomas</lastname> <phone>9947267690</phone> <housename>Grace Villa</housename> <street>III Cross</street> <city>Pattom</city> </person>')~ -
To ensure that data is properly inserted, run the following command from the DB2 Command Editor. DB2 provides excellent views of the XML column in two formats: tree view and source view (see Figures 3 and 4).
SELECT * FROM DB2ADMIN.ADDRESSBOOK~
Figure 3. Tree view of the XML field in DB2 XML document viewer.
Figure 4. Source view of the XML field in DB2 XML document viewer.