3.5.3. Data Components

Data components are non-visual elements of screens that provide loading of data from the middle tier, binding it to data-aware visual components and saving changed data back to the middle tier. 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 from the middle tier to containers.

  • DataContext tracks changes in entities and saves changed instances back to the middle tier upon request.

Usually, data components are defined in the screen XML descriptor in the <data> element. They can be injected into the controller in the same way as visual components:

@Inject
private CollectionLoader<Customer> customersDl;

private String customerName;

@Subscribe
protected void onBeforeShow(BeforeShowEvent event) {
    customersDl.setParameter("name", customerName)
    customersDl.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
protected void onBeforeShow(BeforeShowEvent event) {
    getScreenData().loadAll();
}

Please note that screens load data automatically when the @LoadDataBeforeShow annotation is present on the controller class. So programmatic loading is needed only when there is no such anntotation or the annotation value is set to false. It is usually required when you need to set some loading parameters, as in the example above.