Displaying Dynamic Attributes

When you create a new detail or list view in the project with the Dynamic Attributes add-on installed, the framework provides the ability to use the dynamicAttributes facet in XML descriptors.

Another method to showcase dynamic attributes in views is by employing the DynamicAttributesPanel.

Using dynamicAttributes Facet

dynamicAttributes facet enables the display of dynamic attributes in DataGrid or FormLayout associated with a data container containing entities with dynamic attributes.

Include the dynamicAttributes facet to the facets section of the view XML descriptor:

<view xmlns="http://jmix.io/schema/flowui/view"
      xmlns:dynattr="http://jmix.io/schema/dynattr/flowui"
      title="msg://carDetailView.title"
      focusComponent="form">
    <facets>
        <dynattr:dynamicAttributes/>
        <dataLoadCoordinator auto="true"/>
    </facets>
    <!--...-->
</view>

Subsequently, you can choose this view within the Category attribute details on the Visibility tab.

Using DynamicAttributesPanel

If an entity implements the Categorized interface, you have the option to use the DynamicAttributesPanel component to showcase the dynamic attributes associated with the entity. This component facilitates the selection of a category for a specific entity instance and the specification of values for the dynamic attributes within that category.

To integrate the DynamicAttributesPanel component into a detail view, follow these steps:

  • Make sure the category attribute is included into the fetch plan of your categorized entity:

    <data>
        <instance id="carDc"
                  class="com.company.demo.entity.Car">
            <fetchPlan extends="_base">
                <property name="category" fetchPlan="_base"/>
            </fetchPlan>
            <loader/>
        </instance>
    </data>
  • Add the dynamicAttributesPanel visual component to the view:

    <layout>
        <formLayout id="form" dataContainer="carDc">
            <textField id="numberField" property="number"/>
            <textField id="modelField" property="model"/>
            <dynattr:dynamicAttributesPanel dataContainer="carDc"
                                            categoryFieldVisible="true"/>
        </formLayout>
        <!--...-->
    </layout>

Adding Specific Attributes Explicitly

Additionally, you have the option to manually include dynamic attributes on a view. To accomplish this, incorporate the dynamicAttributes facet into the facets section and use the attribute’s code with + prefix when connecting UI components:

<facets>
    <dynattr:dynamicAttributes/>
    <dataLoadCoordinator auto="true"/>
</facets>
<data>
    <instance id="carDc"
              class="com.company.demo.entity.Car">
         <fetchPlan extends="_base">
        </fetchPlan>
        <loader/>
    </instance>
</data>
<layout>
    <formLayout id="form" dataContainer="carDc">
        <!--...-->
        <textField property="+passengerNumberOfSeats"/>
    </formLayout>
    <!--...-->
</layout>