Class DynTabManager
- All Implemented Interfaces:
Serializable
This is a @ViewScoped bean that provides the main API for opening, closing,
selecting, and querying dynamic tabs. It coordinates between the UI (PrimeFaces TabView),
the tab tracking state (DynTabTracker), and the tab definition registry
(DynTabRegistry).
Key responsibilities:
- Opening tabs via
launchTab(String)orlaunchDynamicTab(java.lang.String, java.lang.String, java.lang.String, java.lang.String, boolean, java.lang.Class<?>, java.util.Map<java.lang.String, java.lang.Object>) - Closing tabs via
removeTab(String)and handling tab close events - Selecting tabs and updating the
@TabScopedcontext accordingly - Dispatching
DynTabCDIEventandApplicationCDIEventto all active tab beans - Providing the tab menu model to the UI template
Event dispatch: Events are NOT dispatched via CDI @Observes, because that
mechanism does not work correctly with @TabScoped beans (CDI would create new bean
instances in the wrong scope). Instead, this manager manually iterates through all active
tabs, sets the correct currentTabId for each, and calls the observer method directly.
- Author:
- DynTabs
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddOrSelectTab(DynTab tab) voidprotected voidaddTabListener(DynTab tabToAdd) Hook method called after a tab is added.voidcloseAllActiveTabs(jakarta.faces.event.ActionEvent e) voidManually dispatches an ApplicationCDIEvent to all active tab beans.static DynTabManagergetFirstTabWithIncludePage(String includePage) Finds the first active tab that has the specified includePage.intgetMatchingTab(DynTab compareTab) Finds an active tab that matches the given DynTab's uniqueIdentifier.getMatchingTab(String uniqueIdentifier) voidinit()booleanisActiveTabWithUniqueID(String uniqueIdentifier) voidlaunchDynamicTab(String name, String title, String includePage, String uniqueIdentifier, boolean closeable, Class<?> cdiBeanClass, Map<String, Object> parameters) Dynamically opens a new tab at runtime with the specified parameters.voidOpens a new dynamic tab, or selects an existing tab if one with the same uniqueIdentifier is already open.voidonTabChange(org.primefaces.event.TabChangeEvent event) Handles PrimeFaces TabView tab change events.voidonTabClose(org.primefaces.event.TabCloseEvent event) Handles PrimeFaces TabView tab close events.voidremoveCurrentTab(boolean ignorePendingChanges) voidremoveCurrentTab(jakarta.faces.event.ActionEvent e) protected voidRemoves (closes) the given tab from the active tab list.voidprotected voidprotected voidremoveTabListener(DynTab tabToAdd) Hook method called after a tab is removed.voidsetActiveTabIndex(Integer activeTabIndex) voidsetSelectedTab(DynTab tab) void
-
Constructor Details
-
DynTabManager
public DynTabManager()
-
-
Method Details
-
getTabTracker
-
getTabMenuModel
-
getTabMap
-
getSelectedTabId
-
init
@PostConstruct public void init() -
onTabChange
public void onTabChange(org.primefaces.event.TabChangeEvent event) Handles PrimeFaces TabView tab change events. Called when the user clicks on a different tab header.- Parameters:
event- the PrimeFaces TabChangeEvent
-
getActiveTabIndex
-
setActiveTabIndex
-
setSelectedTabId
-
setSelectedTab
-
getTab
-
onTabClose
public void onTabClose(org.primefaces.event.TabCloseEvent event) Handles PrimeFaces TabView tab close events. Registered as an AJAX listener for the "tabClose" event onp:tabView. Removes the closed tab and cleans up any related dialog visibility state.- Parameters:
event- the PrimeFaces TabCloseEvent
-
removeTab
-
removeTab
-
removeTab
Removes (closes) the given tab from the active tab list.This is triggered by the
p:ajax"tabClose" event on the template'sp:tabView. The method does NOT delete the DynTab instance from the tracker; instead, it moves it to the end of the list and resets its properties (uniqueIdentifier becomes null, active and activated become false). The active tab count (tabTracker.numActive) is decremented by 1.If the removed tab was the currently selected tab, a new tab is automatically selected (the next tab, or the previous one if the removed tab was last).
- Parameters:
tab- the DynTab instance from tabTracker.tabMapforce- if true, allows closing non-closeable tabs
-
removeTabListener
Hook method called after a tab is removed. Override in subclasses to perform custom actions (e.g. executing JavaScript, cleanup).- Parameters:
tabToAdd- the tab that was removed
-
getSelectedTab
-
getIndexOfSelecedTab
public int getIndexOfSelecedTab() -
getCurrentInstance
-
launchTab
Opens a new dynamic tab, or selects an existing tab if one with the same uniqueIdentifier is already open.The
tabNameis the short name without the "DynTab" suffix. For example, if tabName is "Users", it looks up the tab registered as "UsersDynTab" in theDynTabRegistry.- Parameters:
tabName- the tab name without the "DynTab" suffix (e.g. "Users")
-
launchDynamicTab
public void launchDynamicTab(String name, String title, String includePage, String uniqueIdentifier, boolean closeable, Class<?> cdiBeanClass, Map<String, Object> parameters) Dynamically opens a new tab at runtime with the specified parameters.Creates a DynTab instance and opens it. If an active tab with the same
uniqueIdentifieralready exists, selects it instead of opening a new one.This enables opening multiple instances of the same tab type (same includePage and cdiBeanClass) with different parameters, each with its own
@TabScopedCDI bean instance.Example usage from a managed bean:
dynTabManager.launchDynamicTab("VIPProductsDynTab", "VIP Products", "/WEB-INF/include/products/products.xhtml", "VIPProducts", true, ProductsBean.class, Map.of("category", "vip", "discount", true) );- Parameters:
name- the tab name (e.g. "Products")title- the tab title displayed to the userincludePage- the path to the XHTML page to render in the tabuniqueIdentifier- the unique ID for duplicate detectioncloseable- whether the user can close the tabcdiBeanClass- the CDI bean class associated with the tabparameters- the tab parameters map (can be null)
-
getMatchingTab
Finds an active tab that matches the given DynTab's uniqueIdentifier.If the given tab's uniqueIdentifier is null, falls back to matching by includePage.
- Parameters:
compareTab- the DynTab to match against- Returns:
- the matching active tab, or null if none found
-
getMatchingTab
-
isActiveTabWithUniqueID
-
getFirstTabWithIncludePage
Finds the first active tab that has the specified includePage.- Parameters:
includePage- the XHTML page path to search for- Returns:
- the matching active tab, or null if none found
-
addOrSelectTab
-
fireApplicationEvent
Manually dispatches an ApplicationCDIEvent to all active tab beans. Same principle asfireDynTabEvent(dyntabs.DynTabCDIEvent)- iterates through tabs, sets the correct TabScope, and calls the observer directly.Called from
BaseDyntabCdiBean.sendMessageToAppModule(java.lang.String, java.lang.Object)instead of CDIeventPublisher.fire()because@Observesdoes not work with@TabScopedbeans. -
addTab
-
addTabListener
Hook method called after a tab is added. Override in subclasses to perform custom actions (e.g. executing JavaScript, additional initialization).- Parameters:
tabToAdd- the tab that was added
-
removeCurrentTab
public void removeCurrentTab(jakarta.faces.event.ActionEvent e) -
closeAllActiveTabs
public void closeAllActiveTabs(jakarta.faces.event.ActionEvent e) -
getActiveTabList
-
removeCurrentTab
public void removeCurrentTab(boolean ignorePendingChanges)
-