Data Components
Data components are non-visual elements of views that provide loading of data, binding it to data-aware visual components and saving changed data back to the data store.
-
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 view XML descriptor in the <data>
element:
<data readOnly="true">
<collection id="departmentsDc"
class="com.company.onboarding.entity.Department">
<fetchPlan extends="_base">
<property name="hrManager" fetchPlan="_base"/>
</fetchPlan>
<loader id="departmentsDl" readOnly="true">
<query>
<![CDATA[select e from Department e]]>
</query>
</loader>
</collection>
</data>
Data components can be injected into the controller in the same way as visual components:
@ViewComponent
private CollectionContainer<Department> departmentsDc;
Data components of a particular view are registered in the ViewData
object which is associated with the controller and available through its getViewData()
method. This object is useful when you need to load all data for the view, for example:
@Subscribe
public void onReady(final ReadyEvent event) {
getViewData().loadAll();
}
Use DataLoadCoordinator facet for declarative linking of data loaders to data containers, visual components and view events. |