Dynamicforeach (element)

From JRapid

Jump to: navigation, search

dynamicforeach is an element, child of property.

Contents

Description

Dynamicforeach element is similar to foreach due to its nature.

The foreach element is useful when you have an entity A which specifies an embedded inline collection property of an entity B and you want that collection to be automatically loaded with elements of an entity C.

In the case these elements depend on some other property that the user may change dynamically, you need to use dynamicforeach.


Usage

<dynamicforeach 
        select = SELECT
        setproperty = PROPERTY
        trigger = TRIGGER
/>

Short example

We have this business model: An office supplies system, having a Product entity, which belongs to a category (could be papers, rulers, markers, etc.). Depending on the category, different attributes need to be specified, for example: if we are loading a ruler we specify its size and transparency, if we load markers we specify its color and tip. These attributes are stored in an entity named ProductCategoryAttribute.

File:Dynamicforeach1.jpg


So, the screens we will have in the end should look a little bit like these:

File:Dynamicforeach2.jpg File:Dynamicforeach3.jpg

In each of the previous examples, when we change the category select box, the attributes list is reloaded with the related attributes.


We can load some categories, with its related attributes:

File:Dynamicforeach6.jpg

File:Dynamicforeach4.jpg


And then, in the ProductCategoryAttribute listing we will see:

File:Dynamicforeach5.jpg


The XML used for this example is:


<entity label="Product" name="Product">
        <property display="primary" label="Name" name="name"/>
        <property display="secondary" entity="ProductCategory" label="Category" name="category"/>
        <property childproperty="product" collection="sortedset" display="secondary" embedded="inline" entity="ProductAttribute" label="Attributes" name="attributes" setorder="attribute">
            <dynamicforeach select="ProductCategoryAttribute:findManyBy('productCategory',category)" setproperty="attribute" trigger="onload">
                <param entity="ProductCategory" name="category" value="category"/>
            </dynamicforeach>
        </property>
    </entity>


    <entity label="ProductCategory" name="ProductCategory">
        <property display="primary" label="Name" name="name"/>
        <property childproperty="productCategory" collection="set" embedded="inline" entity="ProductCategoryAttribute" extendable="extendable" label="Attributes" name="attributes"/>
    </entity>

    <entity label="ProductAttribute" name="ProductAttribute">
        <property display="primary" entity="Product" label="Product" name="product"/>
        <property entity="ProductCategoryAttribute" fixed="fixed" label="Attribute" name="attribute"/>
        <property label="Value" name="value"/>
    </entity>

    <entity label="ProductCategoryAttribute" name="ProductCategoryAttribute">
        <property display="secondary" entity="ProductCategory" label="Category" name="productCategory"/>
        <property display="primary" label="Attribute" name="attribute"/>
    </entity>

See also

Personal tools