Using Zen
Zen Application Concepts
[Back] [Next]
Go to:

A Zen application specifies the full set of activities that can result when a Zen client and server interact. These activities may consist of displaying web pages, issuing queries to a database, writing data to disk, and more. When you create a Zen application, you create a suite of Zen classes that specify these activities. The language you use for these classes is Caché ObjectScript — with embedded snippets of XML, HTML, SVG, and JavaScript as needed.

If you are new to Caché objects and the ObjectScript programming language, the discussion in this chapter makes most sense after you have mastered the supporting material available in other books. The best starting points are the books Using Caché Objects and Using Caché ObjectScript.
The examples in this book use ObjectScript, but you can also use Caché Basic, or Caché MVBasic as your programming language. See the books Using Caché Basic or Using the MultiValue Features of Caché.
Client and Server
Zen is a client/server web technology. The terms client and server are commonly used; this section explains how Zen uses these terms.
Zen and CSP
The book Using Caché Server Pages (CSP) describes the relationship between the client and server in CSP applications. It outlines the flow of events between issuing the HTTP request and displaying the page in the browser. Zen applications and Zen pages are CSP pages, so all of this information also applies to Zen.
Zen applications use CSP technologies to:
If you make use of the CSP session preserve mode, be aware that the server-side Zen page (%page) and application (%application) objects are not preserved between server requests.
Zen Pages at Runtime
A Zen page automatically responds to Hypertext Transfer Protocol (HTTP) requests from a browser and serves up a complete HyperText Markup Language (HTML) document to satisfy such a request. Zen pages can also satisfy other types of requests, such as for eXtensible Markup Language (XML) or Scalable Vector Graphics (SVG) content. The behavior for XML or SVG is documented in later chapters. It is similar to the HTML behavior documented in this chapter.
The following sequence displays a Zen page in a browser window:
  1. The web browser sends an HTTP request that names a specific Zen page. The Caché server receives the request and automatically routes it to the Zen page class.
  2. The page class invokes its %OnBeforeCreatePage() callback method. This method provides the opportunity for the application to perform any setup work that may be required before %CreatePage() begins execution.
  3. The page class creates an instance of itself on the Caché server and invokes its class method %CreatePage(). This method creates the set of component objects and adds these objects as children of the page object.
    When a Zen page class contains a description of the page in XML format within an XData Contents block, Zen automatically generates a %CreatePage() method whenever the class is compiled. The compiler uses the information in XData Contents to generate the method. This is by far the most common case. Alternatively, a programmer may omit the XData Contents block and implement %CreatePage() manually. This gives the opportunity to create dynamic page content.
    However, most Zen application developers choose to set up an initial Document Object Model (DOM) for the page using XData Contents, then add finishing touches to this model in %OnAfterCreatePage().
  4. The page class invokes its %OnAfterCreatePage() callback method. In this method, the application can modify the content generated by %CreatePage() in any way that is needed. After %OnAfterCreatePage() completes execution, there is a page object in memory that contains some number of child component objects.
  5. The page object constructs an HTML document from its DOM by invoking the page class’s %DrawHTML() method. Every Zen page and component object has a %DrawHTML() method that knows how to render the object as HTML. In the case of a Zen page, the %DrawHTML() method supplies:
    As with %CreatePage(), for the most part a Zen programmer can ignore %DrawHTML(). Caché generates and invokes it automatically. The important fact about %DrawHTML() is when it occurs. %DrawHTML() is the last step before the page leaves the server.
    The Zen programmer must ensure that all server-side adjustments to the page are complete before the end of the %OnAfterCreatePage() method.
  6. The Caché server delivers the HTML document to the client.
  7. If there is an onloadHandler() client-side method defined in the page class, it runs on the client side at this time.
  8. The browser displays the HTML document
As described above, the Zen application development framework offers several opportunities to manipulate the Zen page prior to its initial display. The most frequently used are as follows
Zen Applications
A Zen application consists of the following parts:
An Application class
A class derived from %ZEN.application that provides application-wide behavior such as a common style sheet. The style sheet is specified as an XML block embedded within the class.
Page classes
A Zen application consists of one or more Zen pages. Each page is a class derived from which is, in turn, a subclass of both %CSP.Page and %ZEN.Component.component.
Component classes
Every page contains components. Components provide “look and feel” and permit the user to interact with the page. All components are derived from %ZEN.Component.component. They include buttons, tables, list boxes, text fields, panels — essentially any item that can be displayed on a page.
Zen Application with Pages and Components
This architecture works as follows:
For programming details, see the Zen Applications chapter in Developing Zen Applications.
Zen Page Synchronized on Client and Server at Runtime
Zen Pages
A Zen page class consists of:
For programming details, see the Zen Pages chapter in Developing Zen Applications.
Defining the Look and Feel of a Zen Page
Zen Components
Zen component classes define the behavior and layout of the page. Every Zen component has the following characteristics:
Component classes vary in complexity from simple wrappers for native HTML controls to full-featured calendar and grid controls. Components include the following specialized types:
For further details, see the next chapter, Zen Component Concepts.”