Licensed to the Apache Software Foundation (ASF) under one or more

contributor license agreements. See the NOTICE file distributed with

this work for additional information regarding copyright ownership.

The ASF licenses this file to You under the Apache License, Version 2.0

(the “License”); you may not use this file except in compliance with

the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software

distributed under the License is distributed on an “AS IS” BASIS,

WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and

limitations under the License.

layout: docpage title: Jewel DataContainer description: The Jewel DataContainer permalink: /component-sets/jewel/datacontainer

< Jewel Components list

Jewel DataContainer

Reference

Available since version 0.9.4.

ClassExtendsImplements
org.apache.royale.jewel.DataContainer{:target=‘_blank’}Jewel ContainerBase{:target=‘_blank’}Jewel IListWithPresentationModel{:target=‘_blank’}

Note: This component is currently only available for JavaScript.

Overview

The Jewel DataContainer class is a component that displays multiple data items.

This component gets the data through its dataProvider property that receives an ArrayList of data objects. To represent each item the component uses a suitably-configured ItemRenderer class. The component generates dynamically as many instances of its ItemRenderer as there are items in the data provider array, and fills each instance with the appropiate data. By default it uses StringItemRenderer as the item renderer.

By default items are laid out vertically using Jewel VerticalLayout. This component has a Viewport that clips generated items.

Example of use

In MXML declare a DataContainer like this:

<j:DataContainer width="100%" height="250">
    <js:ArrayList localId="avengers" source="[Iron Man, Hulk, Thor, Captain America, Black Widow, Hawkeye]"/>
</j:DataContainer>

Note that we can nest the ArrayList directly to the DataContainer tag because “dataProvider” is its DefaultProperty.

In ActionScript we can do the same in the following way:

var dc:DataContainer = new DataContainer();
dc.dataProvider = new ArrayList(["Iron Man", "Hulk", "Thor", "Captain America", "Black Widow", "Hawkeye"]);
// add the Container to the parent
parent.addElement(dc);

where parent is the container where the control will be added.

Relevant Properties and Methods

Check the Reference of org.apache.royale.jewel.DataContainer{:target=‘_blank’} for a more detailed list of properties and methods.

Properties

PROPERTYTypeDescription
currentStateStringThe name of the current state.
itemRendererStringThe class or factory used to display each item.
labelFieldStringThe name of field within the data used for display.
dataProviderObjectThe data being display by the List. Is the DefaultProperty. In Jewel an ArrayList{:target=‘_blank’}
numElementsintThe number of element children that can be laid out.
statesArrayThe array of view states. These should be instances of org.apache.royale.states.State{:target=‘_blank’}
strandChildrenIParent{:target=‘_blank’}An object to access the immediate children of the strand.

Methods

MethodParametersDescription
addElementc(IChild), dispatchEvent(Boolean=true)Add a component to the parent.
addElementAtc(IChild), index(int), dispatchEvent(Boolean=true)Add a component to the parent at the specified index.
getElementIndexc(IChild)Gets the index of this subcomponent.
getElementAtindex(int)Get a component from the parent at specified index.
removeElementc(IChild), dispatchEvent(Boolean=true)Remove a component from the parent.

Relevant Events

The most important event is initComplete, which indicates that initialization of the container is complete.

It is needed when some action coded in a callback function needs to be triggered when the data container is ready to use after initialization.

You can attach callback listeners to the initComplete event in MXML as follows:

<j:DataContainer initComplete="initCompleteHandler(event)"/>

the initComplete event will use the initCompleteHandler callback function you provide in ActionScript:

<fx:Script>
    <![CDATA[      
        private function initCompleteHandler(event:Event):void {
            trace("Container is ready!");
        }
    ]]>
</fx:Script>

When the data container is initialized the message “Container is ready!” appears in the console log.

In ActionScript we can add an event handler this way:

var dc:DataContainer = new DataContainer();
dc.addEventListener('initComplete', initCompleteHandler);
parent.addElement(dc);

Relevant Beads

Bead TypeImplementationDescription
DataProviderModel{:target=‘_blank’}org.apache.royale.core.IBeadModel{:target=‘_blank’}This is the default model bead.
DataContainerView{:target=‘_blank’}org.apache.royale.core.IBeadView{:target=‘_blank’}This is the default view bead.
VerticalLayout{:target=‘_blank’}org.apache.royale.core.IBeadLayout{:target=‘_blank’}This is the default layout bead.
DataItemRendererFactoryForCollectionView{:target=‘_blank’}IDataProviderItemRendererMapper{:target=‘_blank’}Map data to itemrenders.
ItemRendererClassFactory{:target=‘_blank’}IItemRendererClassFactory{:target=‘_blank’}The factory of itemrenders.
StringItemRenderer{:target=‘_blank’}org.apache.royale.core.IItemRenderer{:target=‘_blank’}The itemrenders class to instantiate.
DataContainerItemRendererInitializer{:target=‘_blank’}IItemRendererInitializer{:target=‘_blank’}Configuration of itemrenders to instantiate.
Viewport{:target=‘_blank’}org.apache.royale.core.IViewport{:target=‘_blank’}Define the area that display content.

Common Beads

Jewel DataContainer can use any of the layout beads available in the Jewel library. Also you can check the Related controls section to see some advanced or preconfigured data containers.

More examples

Related controls

Other useful Jewel containers components are: