Class DynTab
- All Implemented Interfaces:
Serializable
Each DynTab instance holds the tab's metadata (title, include page, parameters,
unique identifier) and a reference to its CDI-managed backing bean. Tabs are created
by DynTabRegistry and managed by DynTabManager.
Key properties:
id- internal ID (e.g. "r0", "r1"), matches thep:tabID in the templateincludePage- path to the XHTML page rendered inside this tabuniqueIdentifier- used to detect duplicate tabs (prevents opening the same tab twice)cdiBean- the@TabScopedCDI bean associated with this tabparameters- key-value map passed to the bean (supports EL expressions)
CDI bean lifecycle: The bean class is stored via setCdiBeanClass(Class)
at tab creation time, but the actual bean instance is only resolved later via
resolveCdiBean() when the TabScope is active (i.e., currentTabId is set).
This two-phase approach is necessary because @TabScoped beans require an active
tab context for creation.
- Author:
- DynTabs
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcloseDialog(jakarta.faces.event.ActionEvent e) Returns the CDI bean associated with this tab.Class<?> getId()static DynTabgetInstance(String tabName) Deprecated.getName()getTitle()voidhandleDlgClose(org.primefaces.event.CloseEvent event) Handles the PrimeFaces dialog close event by removing the visibility flag for the closed dialog from the visible map returned bygetDynTabVisibleMap().booleanbooleanisActive()Returns whether this tab is currently active (visible on screen).booleanbooleanChecks whether a dialog component should be visible in this dynamic tab, using the component's client ID as the lookup key.booleanChecks whether a component should be visible in this dynamic tab, using the component's simple ID as the lookup key.voidResolves the CDI bean instance from the CDI container using the storedcdiBeanClass.voidsetActivated(boolean activated) voidsetActive(boolean isActive) voidsetCdiBean(DyntabBeanInterface cdiBean) voidsetCdiBeanClass(Class<?> cdiBeanClass) voidsetCloseable(boolean isCloseable) voidvoidsetIncludePage(String includePage) voidvoidsetParameters(Map parameters) voidvoidsetUniqueIdentifier(String uniqueIdentifier)
-
Constructor Details
-
DynTab
public DynTab()Default constructor. -
DynTab
-
-
Method Details
-
getCdiBeanClass
-
setCdiBeanClass
-
resolveCdiBean
public void resolveCdiBean()Resolves the CDI bean instance from the CDI container using the storedcdiBeanClass.MUST be called AFTER
TabScopedContextHolder.setCurrentTabId(String)has been set, because@TabScopedbeans require an active tab context.If
cdiBeanis already set (e.g. manually viasetCdiBean(dyntabs.interfaces.DyntabBeanInterface)), does nothing. IfcdiBeanClassis not set, also does nothing (tab without a bean). -
setCdiBean
-
getCdiBean
Returns the CDI bean associated with this tab.IMPORTANT: Before returning the bean (which is a proxy for
@NormalScope), this method setscurrentTabIdto this tab's ID. This ensures that when a method is invoked on the proxy,TabContext.get(jakarta.enterprise.context.spi.Contextual<T>, jakarta.enterprise.context.spi.CreationalContext<T>)uses the correct tab context - THIS tab's context, not the currently selected tab's context.This solves the problem that occurs when
c:forEachrenders all tabs at once whilecurrentTabIdis set to the selected tab. Without this, accessing the bean from a non-selected tab would create a new instance in the wrong scope.- Returns:
- the CDI bean for this tab, or null if no bean is associated
-
getId
-
setId
-
getName
-
setName
-
isActive
public boolean isActive()Returns whether this tab is currently active (visible on screen). Active tabs are displayed asp:tabcomponents in the UI template.- Returns:
- true if the tab is active and visible
-
setActive
public void setActive(boolean isActive) -
getTitle
-
setTitle
-
getUniqueIdentifier
-
setUniqueIdentifier
-
getIncludePage
-
setIncludePage
-
setActivated
public void setActivated(boolean activated) -
isActivated
public boolean isActivated() -
setCloseable
public void setCloseable(boolean isCloseable) -
isCloseable
public boolean isCloseable() -
getInstance
Deprecated.This method is tied to the old approach where tabs were registered as<managed-bean>infaces-config.xml. Since Jakarta EE 10+, managed beans are no longer supported. UseDynTabRegistry.createTab(String)instead.Example:
// Old way (deprecated): DynTab tab = DynTab.getInstance("Users"); // New way: @Inject private DynTabRegistry registry; ... DynTab tab = registry.createTab("UsersDynTab");Looks up the DynTab bean for the given tab name from the JSF expression context.- Parameters:
tabName- the tab name (without "DynTab" suffix)
-
setParameters
-
getParameters
-
isComponentVisibleByClientId
Checks whether a dialog component should be visible in this dynamic tab, using the component's client ID as the lookup key.Usage in XHTML:
visible="#{dynTab.isComponentVisibleByClientId(fn:replace(component.clientId,':','_'))}"The method looks up the given key in the JSF view scope map and returns
trueif a Booleantruevalue exists for that key,falseotherwise.- Parameters:
key- the component's client ID (with colons replaced by underscores)- Returns:
- true if the dialog should be visible
-
isComponentVisibleById
Checks whether a component should be visible in this dynamic tab, using the component's simple ID as the lookup key.Usage in XHTML:
visible="#{dynTab.isComponentVisibleById(component.id)}"- Parameters:
key- the component's ID- Returns:
- true if the component should be visible
-
getDynTabVisibleMap
-
getTabSubviewClientId
-
handleDlgClose
public void handleDlgClose(org.primefaces.event.CloseEvent event) Handles the PrimeFaces dialog close event by removing the visibility flag for the closed dialog from the visible map returned bygetDynTabVisibleMap().- Parameters:
event- the PrimeFaces CloseEvent
-
closeDialog
public void closeDialog(jakarta.faces.event.ActionEvent e)
-
<managed-bean>infaces-config.xml.