NaturalONE Version 8.3.7
 —  Custom Controls  —

Control Concept

This document covers the following topics:


Page Generation

The page generation is the process of transferring an XML layout definition into an HTML/JavaScript page. It is automatically executed inside the Layout Painter when previewing a layout. It can also be called from outside.

Page generation

A generator program (com.softwareag.cis.gui.generate.HTMLGenerator) is receiving a string which contains the XML layout definition. The generator program parses this string with an XML parser and as a consequence processes the string tag by tag.

The generation of HTML pages is done in two steps:

A tag handler instance is called at three different points of time by the generator:

It is now the task of the tag handler to create HTML/JavaScript statements at the right point of time.

Top of page

Tag Handlers and Macro Tag Handlers

As described above for the HTML generation, control-specific tag handlers are called. The macro execution is either completely done based on XML definitions (see Creating Macro Controls Out of Existing Controls) or you can also implement a specific macro tag handler. This macro tag handler is then called during the macro execution. In case the macro execution is completely done based on XML definitions, a general macro tag handler is used internally.

Macro tag handlers and tag handlers are Java classes which implement specific interfaces. The corresponding classes are applied to the tags via the following naming convention: for a tag <mytag>, the corresponding Java class must have the name "MYTAGHandler".

The following topics describe the tag handler and the macro tag handler interfaces in more detail:

Macro Tag Handlers (IMacroTagHandler)

The interface com.softwareag.cis.gui.generate.IMacroTagHandler contains two methods which represent the different points of time when the generator calls the tag handler during the macro execution phase.

package com.softwareag.cis.gui.generate;

import org.xml.sax.AttributeList;
import com.softwareag.cis.gui.protocol.ProtocolItem;

public interface IMacroTagHandler
{
    public void generateXMLForStartTag(String tagName,
                                AttributeList attrlist,
                                StringBuffer sb,
                                ProtocolItem pi);
    public void generateXMlForEndTag(String tagName,
                                     StringBuffer sb);
}

Detailed information about the methods can be found inside the Javadoc documentation which is part of your NaturalONE installation. See also Developing Java Extensions in the Ajax Developer documentation.

Tag Handlers (ITagHandler)

The interface com.softwareag.cis.gui.generate-ITagHandler contains three methods that represent the different points of time when the generator calls a tag handler during the HTML generation phase.

package com.softwareag.cis.gui.generate;

import org.xml.sax.AttributeList;
import com.softwareag.cis.gui.protocol.*;

public interface ITagHandler
{
    public void generateHTMLForStartTag(int id,
                                        String tagName,
                                        AttributeList attrlist,
                                        ITagHandler[] handlersAbove,
                                        StringBuffer sb,
                                        ProtocolItem protocolItem);

    public void generateHTMLForEndTag(String tagName,
                                      StringBuffer sb);

    public void generateJavaScriptForInit(int id,
                                          String tagName,
                                          StringBuffer sb);
}

Detailed information about the methods can be found inside the Javadoc documentation which is part of your NaturalONE installation. See also Developing Java Extensions in the Ajax Developer documentation.

Call Sequence (IMacroTagHandler and ITagHandler)

A tag is processed by the generator in a certain way that is now described for the HTML generation phase. (The macro execution phase is processed in a similar way.)

The following image illustrates the call sequence for tag handlers:

Call sequence

Be aware of the following:

Extensions of IMacroTagHandler and ITagHandler

There are certain interfaces which extend the framework for specific situations:

You do not need to know anything about these extensions to create your first controls. Documentation is provided inside the Javadoc documentation. See also Developing Java Extensions in the Ajax Developer documentation.

Top of page

Library Concept

The library concept is responsible for defining the way how the generator finds a tag handler class for a certain tag. There are two situations:

  1. The generator finds a tag without a ":" character. This indicates that this is a control from the Natural for Ajax product - the according tag handler is found inside the package com.softwareag.cis.gui.generate, the class name is created by converting the tag name to upper case and appending "Handler".

    For example, if the generator finds the tag "header", it tries to use a tag handler class com.softwareag.cis.gui.generate.HEADERHandler.

  2. The generator finds a tag with a ":" character, for example, demo:address. This indicates that an external control library is used. There is a central configuration file (<installdir>/config/controllibraries.xml) which contains the external control library names and the corresponding Java package names. Besides this central configuration file, also corresponding configuration files on the user interface level are supported. This is explained later. After having found the package name, the class name is built in the same way as with standard Application Designer controls.

    For example, if the generator finds the tag demo:address and in the configuration file the demo prefix is assigned to the package com.softwareag.cis.demolibrary, then the full class name of the tag handler is com.softwareag.cis.demolibrary.ADDRESSHandler.

What happens if the generator does not find a valid class for a certain tag? In this case, it just copies the tag of the layout definition inside the generated HTML/JavaScript string. Via this mechanism, it is possible to define, for example, HTML tags inside the layout definition which are just copied into the HTML/JavaScript generation result.

When writing your own controls, be sure to use a tag name with your own prefix (such as test:mycontrol) and use your own Java package name which must not start with com.softwareag. The tag names without prefixes and the Java package com.softwareag are reserved for the Natural for Ajax product.

Control Libraries

A control library is a Java library containing ItagHandler/IMacroTagHandler implementations. The corresponding .jar or .class files can be copied either to the central WEB-INF/lib or WEB-INF/classes directory of the cisnatural web application, or they can be copied to the ./appclasses/lib or ./appclasses/classes subdirectory of a user interface component.

The central control file for configuring control libraries in your installation is the file <webappdir>/cis/config/controllibraries.xml. An example of the file looks as follows:

<controllibraries>
	<library package="com.softwareag.cis.demolibrary"
	         prefix="demo">
	</library>
</controllibraries>

Each library is listed with its tag prefix and with the package name in which the generator looks for tag handler classes.

As an alternative to this central control file, you can have a file ./cisconfig/controllibraries.xml in your user interface component (for example, njxdemos/cisconfig/controllibraries.xml). The format of this file is identical to the central control file controllibraries.xml.

Top of page

Binding Concept

The normal binding concept between a page and a corresponding class is:

Top of page

Integrating Controls into the Layout Painter

Once having created new controls, you want to use them inside the Layout Painter. The Layout Painter is configured by a set of XML files.

The files with the name editor_*.xml are used to extend the Layout Painter with your own custom controls. These editor_*.xml files can either be located centrally in <webappdir>/cis/config/ or in a subfolder cisconfig of a user interface component.

There is a central file editor.xml which defines the central controls that come with the Natural for Ajax framework. For each control, the properties and how the control fits into other controls is defined. In addition, data type definitions to provide value help for the properties are defined inside this file.

In short: editor.xml controls the way in which controls are presented inside the Layout Painter.

When creating new controls, you want to integrate your controls into the Layout Painter, that is, you want to register them inside editor.xml as well. Instead of letting you directly manipulate editor.xml, there is an extension concept - in order to keep your definitions untouched by release upgrades. Again naming conventions are used: for a control library named "demo", you would define your controls in a file with the name editor_demo.xml. This means that you will have one editor_*.xml file per control library.

Have a look at the editor_demo.xml file:

<!-- DEMO:ADDRESSROWAREA2 -->
  <tag name="demo:addressrowarea2">
    <attribute name="addressprop" mandatory="true"/>
    <protocolitem>
    </protocolitem>
  </tag>
  <tagsubnodeextension control="pagebody" newsubnode="demo:addressrowarea2"/>

In this example, a new control demo:addressrowarea2 is defined:

Or have a look at the following section:

<!-- DEMO:ADDRESSROWAREA3 -->
  <tag name="demo:addressrowarea3">
    <attribute name="addressprop" mandatory="true"/>
    <taginstance>
      <rowarea name="Address">
          <itr>
              <label name="First Name" width="100">
              </label>
              <field valueprop="$addressprop$.firstName" width="150">
              </field>
          </itr>
          <itr>
              <label name="Last Name" width="100">
              </label>
              <field valueprop="$addressprop$.lastName" width="150">
              </field>
          </itr>
          <vdist height="10">
          </vdist>
          <itr>
              <label name="Street" width="100">
              </label>
              <field valueprop="$addressprop$.street" width="300">
              </field>
          </itr>
          <itr>
              <label name="Town" width="100">
              </label>
              <field valueprop="$addressprop$.zipCode" width="50">
              </field>
              <hdist width="5">
              </hdist>
              <field valueprop="$addressprop$.town" width="245">
              </field>
          </itr>
          <vdist height="10">
          </vdist>
          <itr>
              <hdist width="100">
              </hdist>
              <button name="Clear" method="$addressprop$.clearAddress">
              </button>
          </itr>
      </rowarea>
    </taginstance>
    <protocolitem>
        <addproperty name="$addressprop$" datatype="ADDRESSInfo" useincodegenerator="true"/>
    </protocolitem>
  </tag>
  <tagsubnodeextension control="pagebody" newsubnode="demo:addressrowarea3"/>

The control demo:addressarea3 has the following features:

Whenever possible we recommend to use the Control Editor to create and edit the editor_*.xml files.

Note:
If you are working with NaturalONE, see Ajax Developer in the NaturalONE documentation for details on using the Control Editor. If you are working with the standalone version of Natural for Ajax, see Development Workplace in the Application Designer documentation, which is included in the Natural for Ajax distribution package, for details on using the Control Editor.

Top of page

Summary

When defining new controls, there are the following resources:

The next section contains examples for building macro controls and new controls.

Top of page