XML.com: XML From the Inside Out
oreilly.comSafari Bookshelf.Conferences.

advertisement

Introducing OpenLaszlo
by Sreekumar Parameswaran Pillai | Pages: 1, 2, 3, 4, 5

A Quick Look At Laszlo Web-Application Architecture

We'll take a look at the basic architecture of an OpenLaszlo-based web application from a configuration perspective. An in-depth discussion is beyond the scope of the present article, but is provided in the Laszlo Developer's Guide, available here.

Role of the Laszlo Presentation Server (LPS)

The Laszlo Presentation Server houses the Laszlo application that communicates with the client (browser). In terms of tiered web-application architecture, LPS is responsible for creating the view (presentation). The Laszlo files are compiled at the server and downloaded to the client as .swf files to be rendered by the Flash plugin in the browser. However, the data transported to the view is in XML format.

Role of the Tomcat (Servlet Container)

The application server houses the web application that executes business logic and communicates with the LPS. The Laszlo installation package is bundled with a Tomcat 5.0 server preconfigured with the LPS server. It is convenient for development purposes.

Now, we need to create the web application and deploy it to the Tomcat server. This is nothing but a jsp file that returns one single message: "Hello World from the Server!!" to our helloworld.lzx. This basic application will also help us validate the current deployment configuration.

First of all, from the current Laszlo perspective, update helloworld.lzx with the following:

Listing 2. helloworld.lzx

<canvas width="800" height="600">
<dataset name="hw_dset" src="/2006/10/11/graphics/http://localhost:8080/laszlotutorial/message.jsp" type="http" request="true"/>
<window name="mainwindow" width="250" height="150" title="Hello World">
<simplelayout axis="y" spacing="10"/>
<text text="Hello World" fontsize="14" fontstyle="bold" />
<text width="250" datapath="hw_dset:/laszlotutorial/message/@text" fontsize="10" fontstyle="bold" />
</window>
</canvas>

The above file is not much different from the first helloworld.lzx we created earlier, except for the following:

  1. We have created a data source for the XML data that the application layer will provide.

  2. The src attribute of the dataset must point to the URL of the jsp or the controller in the application layer.

  3. The type denotes the type of request sent to the server.

  4. The Boolean value for the request tells LPS whether the data should be accessed immediately when the dataset is instantiated, or whether data will be required only during runtime while it is explicitly requested. In the latter case, the request attribute should be set to false, meaning "the data is not requested when the dataset object is instantiated," and the request for data is deferred at the time of instantiation.

With this, we have integrated the Laszlo code to accept dynamic data from the application layer.

Creating the Java Web Project

  1. Select File >> New… >> Project >> and in the wizard box, select Dynamic Web Project and click Next.

  2. Enter the name of the project as "laszloweb".

  3. Select default entries for the other items and click Finish.

New Dynamic Web Project Wizard
Figure 13. The New Dynamic Web Project wizard

  1. When asked "Open Associated Perspective dialog box?", click yes.

  2. This editor opens up with the J2EE perspective.

  3. For convenience, you can hide the irrelevant folders by configuring the Working Sets in Eclipse. The Project Explorer finally looks like Figure 14.

The Project Explorer
Figure 14. The Project Explorer with the Laszlo and Laszlo web projects

  1. Right-click the Web Content folder in laszloweb project, and select New... >> JSP.

  2. Give the name as message.jsp and click Finish.

  3. Copy and paste the following code snippet to message.jsp.

  4. This just sets the contentType of the jsp to XML and ensures that well-formed XML is returned to the client.

Listing 3. message.jsp

<%@ page contentType="text/xml" %>
<laszlotutorial>
<message text="Hello World from the server!!"/>
</laszlotutorial>

Pages: 1, 2, 3, 4, 5

Next Pagearrow