Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
HTML Wrap
floatright
classmenu

Related topics:

Item providers are a means for accessing items from data sources. On this page, we describe provide more information about what item providers are, list their main advantages and show a few examples of using them.

Table of Contents

Overview

The concept of Item providers are a means for accessing items from data sourcesis an abstraction aiming to give developers a flexible way to specify which item a form field (simple or complex) should bind to and how the item schould be accessed. 

  • It allows to bind form views to complex nested datastructures and fine tune such binding. E.g. if a form binds a contact address as a separate sub-form (in M5 words - e.g. as a composite field), the Magnolia user might want to use a contact's child node to store the data (item provider that resolves a sub-node can be used), or store the properties directly on the contact node keeping it flat (self-reference item provider case).
  • item providers get reference items as context. I.e. an address editor from the example upon data binding will get the root contact node so that it would be trivial to resolve the corresponding sub-node if needed. Forms are always populated and persisted from top of the hierarchy to the bottom.
  • Item providers kick in the form lifecycle only twice (typically): when the data is fetched from the backend (to populate the form) and when the updated data needs to be flushed from the Vaadin components back to the backend (on form commit).
  • item providers yield items wrapped into Optional container, so it is fine not to return anything from the item provider implementation (in such case though, the form data may not be populated or saved back to the backend).

Where are they used

Item providers are used in the following two use cases:

...

In a sub app definition, a strategy is implemented for example in the Pages app, where the jcrNodeFromLocationProvider is used (see line 7 below). This provider type resolves a JCR node from its location context:

Code Block
languageyml
linenumberstrue
  detail:
    class: info.magnolia.pages.app.detail.PageDetailDescriptor
    datasource:
      $type: jcrDatasource
      workspace: website
    itemProvider:
      $type: jcrNodeFromLocationProvider

...