General Interface is an open source project hosted by the Dojo Foundation

Flexible CDF Schema

The Common Data Format (CDF), enforces a standard XML data schema with a root element called data, nested elements called record and record attributes such as jsxid, jsxtext and jsximg. This schema applies to the classes that implement the jsx3.xml.CDF interface: Select, Tree, Menu, Table and Matrix (and previously List and Grid).

Standard CDF schema example
<data jsxid="jsxroot">
  <record jsxid="1" jsxtext="One" jsximg="one.gif"/>
  <record jsxid="2" jsxtext="Two" jsximg="two.gif"/>
  ...
</data>

The flexible CDF schema feature allows these same classes to consume datasources that do not strictly follow CDF. This feature is particularly useful for consuming pre-existing XML datasources that were created without knowledge of CDF.

With the flexible CDF schema feature,

  • The core CDF schema elements and attributes data, record and jsxid can be renamed to anything
  • A single data source can drive multiple CDF controls, each with its own view of the data
An alternative way of converting data sources to CDF is to use XSL Transformers. XSL Transformers allow you to define one or more XSL transformations to convert the source data to CDF before it is stored in the XML application cache and is used to render a CDF control. Whereas the flexible CDF schema feature supports only XML schemas that have a similar structure to CDF, the XSL transformers approach supports any arbitrary XML schema. Knowledge of XSL is required to use this approach. See the API documentation for jsx3.xml.Cacheable for more information on XML Transformers.

How Flexible CDF Schema Works

Each CDF control has a schema property of type jsx3.xml.CDFSchema. The value of this property defines how the control views its CDF datasource. If the schema property is not set then the control uses the default CDF schema.

Each CDF control first queries its schema for the name of the text attribute and then queries its datasource for that attribute of a record. For example, the implementation of jsx3.gui.Tree includes expressions such as

this.getRecordNode(id).getAttribute(this.getSchema().getProp("text"))

This additional level of indirection (this.getSchema().getProp("text") instead of "jsxtext") allows the CDFSchema object to control how each CDF control views its datasource. The default CDFSchema object returns "jsxtext" from a call to getProp("text"). However, you can modify the schema so that it returns "label" instead. This change would allow you to have a CDF datasource such as

<data jsxid="jsxroot">
  <record jsxid="1" label="One"/>
  ...
</data>

Controlling Flexible CDF Schema in General Interface Builder

You can control flexible CDF schema from within General Interface Builder. To do so,

  1. Open or create a component with a CDF control in it, such as Matrix, Tree or Menu.
  2. Find the CDF Schema component in the Component Libraries palette and drag it onto the CDF control. It may be easier to drag it onto the corresponding node in the Component Hierarchy palette.
  3. Modify the properties of the schema object in the Properties Editor.

The Properties Editor contains an editable property for each attribute in the default CDF schema. In general, the default value of property abc is jsxabc. CDFSchema also has a property called record. This property allows you to change the element name of the records in the datasource. You can choose another name, such as item or you can use set it to * to indicate than any XML element should be interpreted as a data record.

For the CDF schema shown in the screenshot, the datasource is

<items id="jsxroot">
  <item id="1" label="One"/>
  <thing id="2" label="Two"/>
  <object id="3" label="Three"/>
  ...
</items>

Using the same datasource for two different controls is simply a matter of defining a unique CDF schema for each control.

Click to download a sample project that uses the flexible CDF schema feature: GI-702.zip.

Contents

Searching General Interface Docs

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.