This page describes the purpose, scope and use cases of the UIComponentContext in the Magnolia 6 UI framework.
The UiComponentContext is used to share a state between UI components.
Example
import info.magnolia.ui.framework.ContextProperty;
import info.magnolia.ui.framework.UiComponentContext;
publicinterfaceExampleContextextendsUiComponentContext{
ContextProperty<String> value(); //implementation of ContextProperty is created at runtime
}Copy
UiComponentContext has to be injected into a constructor, typically a constructor of a component or an action.
import info.magnolia.ui.ValueContext;
import info.magnolia.ui.framework.ContextProperty;
import javax.inject.Inject;
import com.vaadin.ui.Notification;
publicclassObservation{
@InjectpublicObservation(ValueContext<?> valueContext){
final ContextProperty<?> current = valueContext.current();
current.observeNullable(strings -> Notification.show(strings + " are selected!"));
}
}Copy
Use cases
ValueContext, holds the selection or value that the related UI components operate with.
LocaleContext, used in various editors which:
Allow editing localized content.
Support switching between supported languages within the same session.
FilterContext, a data filter context. Typically, it is mutated by the UI and consumed by Vaadin data providers in order to filter the displayed data sets accordingly.
info.magnolia.ui.contentapp.ContentBrowserSubApp.LocationContext or info.magnolia.ui.contentapp.detail.ContentDetailSubApp.LocationContext, holds the location of a browser or detail subapp.
In the Browser subapp
The ValueContext and LocaleContext are injected into the Browser subapp.
As these contexts have not yet been bound in the parent component, the injection mechanism creates new instances.
The ValueContext changes (the server side updates such a new item creation, for example) are propagated to a grid selection and a grid selection (when the user selects an item, for example) is propagated to the ValueContext).
This mechanism ensures that the ValueContext — injected for example into the actions — points to an up-to-date selection.
Dialogs opened in the grid view are populated from the same instance of the ValueContext.
Link field choosers are a good example of a component specificUIContext. The contexts in the choosers should not be synchronized with the contexts of the underlying grid from which the dialog is opened.
Even though the detail subapps are opened from the same browser, each subapp holds its own ValueContext. Therefore, the form can be written to its own underlying item.