Class UiComponentPolicyContext

java.lang.Object
io.jmix.uiconstraints.accesscontext.UiComponentPolicyContext
All Implemented Interfaces:
AccessContext

@NullMarked public class UiComponentPolicyContext extends Object implements AccessContext
Defines an authorization point for a UI component policy: whether a component or an action of a view may be shown to the current user, and whether it may be modified by them.

The component is addressed exactly as a policy addresses it - by the id of the view and the path of the component relative to that view, for example addressFragment.streetField for a component of a fragment or usersDataGrid.create for an action. Both permissions start as granted, so a component that no policy mentions is reported as permitted.

Example:


 UiComponentPolicyContext context = new UiComponentPolicyContext(viewId, "addressFragment.streetField");
 accessManager.applyRegisteredConstraints(context);

 if (!context.isVisiblePermitted()) {
     // the component must not be shown
 }
 
See Also:
  • Field Details

    • viewId

      protected final String viewId
    • componentPath

      protected final String componentPath
    • visiblePermitted

      protected boolean visiblePermitted
    • enabledPermitted

      protected boolean enabledPermitted
  • Constructor Details

    • UiComponentPolicyContext

      public UiComponentPolicyContext(String viewId, String componentPath)
  • Method Details

    • getViewId

      public String getViewId()
      Returns the id of the view the component belongs to.
    • getComponentPath

      public String getComponentPath()
      Returns the path of the component or action within the view, in the form used by UI component policies.
    • setVisibleDenied

      public void setVisibleDenied()
      Denies showing the component.
    • setEnabledDenied

      public void setEnabledDenied()
      Denies modifying the component: a field is expected to become read-only, any other component disabled.
    • isVisiblePermitted

      public boolean isVisiblePermitted()
      Returns whether the component may be shown.
    • isEnabledPermitted

      public boolean isEnabledPermitted()
      Returns whether the component may be modified.
    • explainConstraints

      public @Nullable String explainConstraints()
      Description copied from interface: AccessContext
      Returns a human-readable explanation of constraints applied to the current context instance for logging of authorization decisions. Null if the current context does not impose any constraints.
      Specified by:
      explainConstraints in interface AccessContext