3.9.1.2. DynamicAttributesPanel

If an entity implements com.haulmont.cuba.core.entity.Categorized interface, you can use DynamicAttributesPanel component for displaying dynamic attributes of this entity. This component allows a user to select a category for the particular entity instance and specify values of dynamic attributes of this category.

In order to use the DynamicAttributesPanel component in an edit screen, do the following:

  • Include the category attribute to the view of your categorized entity:

    <view entity="ref_Car" name="car-view" extends="_local">
        <property name="category" view="_minimal"/>
    </view>
  • Declare an InstanceContainer in the data section:

    <data>
       <instance id="carDc"
                 class="com.company.ref.entity.Car"
                 view="car-view">
          <loader dynamicAttributes="true"/>
       </instance>
    </data>

    Set the dynamicAttributes parameter of the loader to true to load the entity’s dynamic attributes. Dynamic attributes are not loaded by default.

  • Now, the dynamicAttributesPanel visual component may be included in the XML-descriptor of the screen:

    <dynamicAttributesPanel dataContainer="carDc"
                            cols="2"
                            rows="2"
                            width="AUTO"/>

    You can specify the number of columns to display dynamic attributes using the cols parameter. Or you can use the rows parameter to specify the number of rows (in this case, the number of columns will be calculated automatically). By default, all attributes will be displayed in one column.

    On the Attributes Location tab of the category editor, you can more flexibly customize the position of the dynamic attributes. In this case, the values of the cols and rows parameters will be ignored.