Package dyntabs.scope
Class TabContext
java.lang.Object
dyntabs.scope.TabContext
- All Implemented Interfaces:
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:
- When a
@TabScopedbean is accessed, CDI calls theget(jakarta.enterprise.context.spi.Contextual<T>, jakarta.enterprise.context.spi.CreationalContext<T>)method get()usesTabScopedContextHolder.getCurrentTabId()to determine which tab is currently active- Looks up an existing instance for that tab, or creates a new one if none exists
- 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 -
Method Summary
Modifier and TypeMethodDescription<T> Tget(jakarta.enterprise.context.spi.Contextual<T> contextual) Returns an existing bean instance for the current tab, or null if none exists.<T> Tget(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> getScope()Returns the scope annotation class that this Context implements.booleanisActive()Checks whether this Context is currently active.
-
Constructor Details
-
TabContext
public TabContext()
-
-
Method Details
-
getScope
Returns the scope annotation class that this Context implements.- Specified by:
getScopein interfacejakarta.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
@TabScopedbean is accessed.- Specified by:
getin interfacejakarta.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:
getin interfacejakarta.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:
isActivein interfacejakarta.enterprise.context.spi.Context- Returns:
- true if the Context is active (has an active tab)
-