Using Zen Mojo
Creating the Classes
[Home] [Back] [Next]
InterSystems: The power behind what matters   

When you create a Zen Mojo application, most of the work is the task of defining the template class or classes. So that you can start that work as quickly as possible, this chapter describes the prerequisite work of defining a set of interrelated classes as a starting point. It discusses the following topics:

Choosing Plugins and Downloading Files
Early in development, you should decide which plugins you will use. In some cases, you will need to download files for use by a plugin. For a list of plugins and files that they need, see Using Zen Mojo Plugins.
Using the Zen Mojo Wizard
Studio provides a convenient wizard that you can use as a starting point for this set of classes. The wizard generates a page class, a template class, and (optionally) an application class. To use this wizard:
  1. Click File > New, click Zen, and click Zen Mojo Site.
  2. Click OK.
  3. Specify values for some or all of the following options:
    Other than the class names, you can change all the details creating the classes.
  4. Click Finish.
Studio then generates a Zen Mojo page class, template class, and (if you specified Application Class Name) application class, all in the package that you specified for Package Name.
The page class contains preliminary parameter definitions, a preliminary pageContents XData block, and an empty XData Style block. It also specifies the JSINCLUDES and CSSINCLUDES class parameters, based on the helper plugins you selected.
The template class contains preliminary definitions of %OnGetJSONContent(), onGetContent(), and other methods.
The application class (if generated) contains preliminary parameter definitions and an empty XData Style block.
The next step is to examine the page class and modify its pageContents XData block as needed. See Creating a Basic pageContents Definition,” later in this chapter.
Creating Zen Mojo Classes Manually
As an alternative to using the Zen Mojo wizard, you can create the initial application class, page class, and template class manually. This section describes the requirements.
Defining the Zen Mojo Application Class
A Zen Mojo application class is optional.
To define a Zen Mojo application class, define a class that extends %ZEN.Mojo.baseApplication and optionally include a Style XData block in this class. For details, see the chapter Using Style Sheets.”
For additional options for the application class, see the class references for %ZEN.Mojo.baseApplication.
Defining a Zen Mojo Page Class
To create a basic Zen Mojo page class, create a class that extends %ZEN.Mojo.basePage. In your class:
Defining a Template Class
To create a template class, create a class that extends %ZEN.Mojo.Component.contentTemplate. In your class, do the following as a starting point:
Creating a Basic pageContents Definition
In the page class, the pageContents XData block defines the contents of the primary area of the page, as described in Parts of a Zen Mojo Page,” earlier in this book. The following shows the skeletal structure of this XData block:
XData pageContents [ XMLNamespace = "" ]
<pane xmlns="" xmlns:mojo="" layout="none">
  your contents here
In place of your contents here, include one or more <mojo:documentView> elements. For each of these, include a page manager plugin and all needed helper plugins (see the next section, Registering Plugins). Also specify the id attribute of each documentView, as well as either or both of the ongetlayout and ongetdata XML attributes, depending on your needs. For ongetlayout and ongetdata, use values like the following:
return zenPage.getContent('contentObject',key,criteria);
Note that getContent() is a built-in page method and contentObject is the name of a content object provided, ultimately, by the template.
The following shows an example:
XData pageContents [ XMLNamespace = "" ]
<pane xmlns="" 
xmlns:mojo="" layout="none">
   <mojo:documentView id="mainView" developerMode="true"
                      ongetlayout ="return zenPage.getContent('mainViewLayout',key,criteria);">

In this example, child elements are indented for readability. It is not necessary for you to do the same.
Registering Plugins
You should register one or more plugins for use in each documentView. To do so:
The following shows the general structure (with extra indentation for clarity; you do not need to include this indentation):
<mojo:documentView id="mainView" other attributes...>
For details, see Using Zen Mojo Plugins.
If you use custom plugins, it is important to consider the order in which you list the helper plugins, because of the possibility of plugin conflict. A plugin conflict occurs if a single documentView uses multiple helper plugins and those plugins have layout objects with the same name. For all plugins provided by InterSystems, each layout object has a unique name, but custom plugins could potentially have layout objects with the same names as InterSystems layout objects. This is not an error condition, but rather a scenario that requires special handling. For more information, see Detecting and Resolving Plugin Conflicts in Using Zen Mojo Plugins.
Using Multiple documentViews
Depending on the plugins you use, a page can contain multiple documentViews that can affect each other. For example, you could have two documentViews, side by side. The left documentView could display options that control what is shown in the right documentView.
For some plugins, only one documentView is supported. For details, see Using Zen Mojo Plugins. In general, if a page manager plugin is intended for use on mobile devices, that plugin uses the entire page and does not support multiple documentViews.
Next Steps
Now that you have created a set of Zen Mojo classes to use as a starting point, do the following to create your Zen Mojo application:
Later chapters in this book discuss additional topics.

Send us comments on this page
Copyright © 1997-2019 InterSystems Corporation, Cambridge, MA