Data Components

Data components are non-visual elements of screens that provide loading of data, binding it to data-aware visual components and saving changed data back to the data store. There are the following categories of data components:

  • Containers provide the thin layer between entities and data-aware visual components. Different types of containers hold either single instances or collections of entities.

  • Loaders load data to containers.

  • DataContext tracks changes in entities and saves changed instances upon request.

Usually, data components are defined in the screen XML descriptor in the <data> element:

<data readOnly="true">
    <collection id="departmentsDc"
                class="ui.ex1.entity.Department">
        <fetchPlan extends="_base">
            <property name="employees" fetchPlan="_base"/>
        </fetchPlan>
        <loader id="departmentsDl">
            <query>
                <![CDATA[select e from uiex1_Department e]]>
                <condition>
                    <c:jpql>
                        <c:where>e.name like :name</c:where>
                    </c:jpql>
                </condition>
            </query>

        </loader>
        <collection id="employeesDc" property="employees"/>
    </collection>
</data>

Data components can be injected into the controller in the same way as visual components:

@Autowired
private CollectionLoader<Department> departmentsDl;

private String departmentName;

@Subscribe
public void onBeforeShow(BeforeShowEvent event) {
    departmentsDl.setParameter("name", departmentName);
    departmentsDl.load();
}

Data components of a particular screen are registered in the ScreenData object which is associated with the screen controller and available through its getScreenData() method. This object is useful when you need to load all data for the screen, for example:

@Subscribe
public void onAfterShow(AfterShowEvent event) {
    getScreenData().loadAll();
}
Use DataLoadCoordinator facet for declarative linking of data loaders to data containers, visual components and screen events. In case you need to set some loading parameters, you can use programmatic loading as described in the section below.