close

Filter

loading table of contents...

Studio Developer Manual / Version 2107

Table Of Contents

5.4.4 Structs

Structs are part of the Unified API and are thus a core product feature.

Implemented by the interfaces Struct and StructBuilder in the Java API, structs provide a way to store dynamically typed, potentially nested objects in the content repository, and thus add the possibility of storing dynamically structured content to the Content Server's static content type system. To this end, the document type schema may define XML properties with the grammar name coremedia-struct-2008. This grammar should use the XML schema http://www.coremedia.com/2008/struct as defined in coremedia-struct-2008.xsd.

In the ActionScript API, structs are modeled as Bean objects. They are directly modifiable. They implement the additional interface com.coremedia.cap.struct.Struct to provide access to their dynamic type.

Like every content property value, struct beans are provided as properties of the ContentProperties beans. If a struct bean contains a substruct at some property, that substruct is again represented as a struct bean.

Atomic properties of structs may be accessed just like regular bean properties. Structs can store strings, integers, Boolean, and links to documents as well as lists of these values. All struct properties can be read and written using the ordinary Bean interface. As usual, lists are represented as ActionScript Array objects. Do not modify the array returned for a list-valued property. To modify an array, clone the array, modify the clone, and set the new value at the bean.

In the special case of lists of structs, use the methods addAt() and removeAt() (of the struct containing the struct list) to insert or delete individual entries in the struct list. Note that Struct objects in struct lists represent a substruct at a fixed position of the list. For example, the Struct objects at position 2 will contain the values of the struct previously at position 1 after you insert a new struct at position 0 or 1.

Structs and substructs support property change events. Substructs do not support value change events. You can only listen to a single property of a substruct.

Top-level structs in the ActionScript API are never null. If a content property is bound to an empty XML text, a struct without properties is still accessible on the client. This makes it easier to fill initially empty struct properties.

The most convenient way to access a struct property is by means of a value expression. For example, for navigating from a content property bean to the property bar of the struct stored in the content property foo, you would use the property path foo.bar. You can use these property paths in the standard property fields provided by CoreMedia Studio. This case is shown in the following code fragment:

<?xml version="1.0" encoding="UTF-8"?>
<editor:DocumentTabPanel
        xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns="exml:ext.config"
        xmlns:editor="exml:com.coremedia.cms.editor.sdk.config">
  ...
  <editor:items>
    <editor:StringPropertyField propertyName="foo.bar"/>
  </editor:items>
  ...
</editor:DocumentTabPanel>

Example 5.18. Property paths into struct


Structs support the dynamic addition of new property values. To this end, the interface Struct provides access to a type object implementing com.coremedia.cap.struct.StructType through the method getType(). You can call the addXXXProperty() methods for various property types during the initialization code that runs after the creation of a document.

public function init(editorContext:IEditorContext):void {
  ...
  editorContext.registerContentInitializer("MyDocumentType",
    initStruct);
  ...
}

private function initStruct(content:Content):void {
  var properties:ContentProperties = content.getProperties();
  var struct:Struct = properties.get('foo') as Struct;
  struct.getType().addStringProperty('bar', 200);
}

Example 5.19. Adding struct properties


While it is possible to add a property automatically during the first write, this is not recommended. Some property fields cannot handle an initial value of undefined. You should therefore only bind property fields to initialized properties.

Search Results

Table Of Contents
warning

Your Internet Explorer is no longer supported.

Please use Mozilla Firefox, Google Chrome, or Microsoft Edge.