Package dyntabs.scope

Class TabContext

java.lang.Object
dyntabs.scope.TabContext
All Implemented Interfaces:
jakarta.enterprise.context.spi.Context

public class TabContext extends Object implements jakarta.enterprise.context.spi.Context
CDI Context implementation for @TabScoped beans.

This class is the core of the TabScoped mechanism - the CDI container calls it when it needs to create or return an existing instance of a @TabScoped bean.

How it works:

  1. When a @TabScoped bean is accessed, CDI calls the get(jakarta.enterprise.context.spi.Contextual<T>, jakarta.enterprise.context.spi.CreationalContext<T>) method
  2. get() uses TabScopedContextHolder.getCurrentTabId() to determine which tab is currently active
  3. Looks up an existing instance for that tab, or creates a new one if none exists
  4. Returns the instance (actually a proxy, since this is a NormalScope)

IMPORTANT: Before accessing a @TabScoped bean, you MUST call TabScopedContextHolder.setCurrentTabId(String) so the Context knows which tab scope to operate in.

Author:
DynTabs
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> T
    get(jakarta.enterprise.context.spi.Contextual<T> contextual)
    Returns an existing bean instance for the current tab, or null if none exists.
    <T> T
    get(jakarta.enterprise.context.spi.Contextual<T> contextual, jakarta.enterprise.context.spi.CreationalContext<T> creationalContext)
    Returns an existing bean instance for the current tab, or creates a new one.
    Class<? extends Annotation>
    Returns the scope annotation class that this Context implements.
    boolean
    Checks whether this Context is currently active.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • TabContext

      public TabContext()
  • Method Details

    • getScope

      public Class<? extends Annotation> getScope()
      Returns the scope annotation class that this Context implements.
      Specified by:
      getScope in interface jakarta.enterprise.context.spi.Context
      Returns:
      TabScoped.class
    • get

      public <T> T get(jakarta.enterprise.context.spi.Contextual<T> contextual, jakarta.enterprise.context.spi.CreationalContext<T> creationalContext)
      Returns an existing bean instance for the current tab, or creates a new one.

      This is the main method called by CDI when a @TabScoped bean is accessed.

      Specified by:
      get in interface jakarta.enterprise.context.spi.Context
      Parameters:
      contextual - the bean type (contains bean metadata)
      creationalContext - the context for creating a new bean instance
      Returns:
      the bean instance for the current tab
    • get

      public <T> T get(jakarta.enterprise.context.spi.Contextual<T> contextual)
      Returns an existing bean instance for the current tab, or null if none exists.

      Unlike get(Contextual, CreationalContext), this method NEVER creates a new instance - it only returns an existing one or null.

      Specified by:
      get in interface jakarta.enterprise.context.spi.Context
      Parameters:
      contextual - the bean type
      Returns:
      the existing instance, or null if not found
    • isActive

      public boolean isActive()
      Checks whether this Context is currently active.

      The context is active if a current tabId is set, meaning code is executing within the context of some tab.

      Specified by:
      isActive in interface jakarta.enterprise.context.spi.Context
      Returns:
      true if the Context is active (has an active tab)