Package dyntabs

Class DynTabManager

java.lang.Object
dyntabs.DynTabManager
All Implemented Interfaces:
Serializable

@Named @ViewScoped public class DynTabManager extends Object implements Serializable
The central manager for dynamic tabs in the DynTabs framework.

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:

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 Details

    • DynTabManager

      public DynTabManager()
  • Method Details

    • getTabTracker

      public DynTabTracker getTabTracker()
    • getTabMenuModel

      public List<DynTab> getTabMenuModel()
    • getTabMap

      public Map<String,DynTab> getTabMap()
    • getSelectedTabId

      public String 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

      public Integer getActiveTabIndex()
    • setActiveTabIndex

      public void setActiveTabIndex(Integer activeTabIndex)
    • setSelectedTabId

      public void setSelectedTabId(String id)
    • setSelectedTab

      public void setSelectedTab(DynTab tab)
    • getTab

      public DynTab getTab(String id)
    • onTabClose

      public void onTabClose(org.primefaces.event.TabCloseEvent event)
      Handles PrimeFaces TabView tab close events. Registered as an AJAX listener for the "tabClose" event on p:tabView. Removes the closed tab and cleans up any related dialog visibility state.
      Parameters:
      event - the PrimeFaces TabCloseEvent
    • removeTab

      public void removeTab(String id)
    • removeTab

      protected void removeTab(String id, boolean force)
    • removeTab

      protected void removeTab(DynTab tab, boolean force)
      Removes (closes) the given tab from the active tab list.

      This is triggered by the p:ajax "tabClose" event on the template's p: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.tabMap
      force - if true, allows closing non-closeable tabs
    • removeTabListener

      protected void removeTabListener(DynTab tabToAdd)
      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

      public DynTab getSelectedTab()
    • getIndexOfSelecedTab

      public int getIndexOfSelecedTab()
    • getCurrentInstance

      public static DynTabManager getCurrentInstance()
    • launchTab

      public void launchTab(String tabName)
      Opens a new dynamic tab, or selects an existing tab if one with the same uniqueIdentifier is already open.

      The tabName is the short name without the "DynTab" suffix. For example, if tabName is "Users", it looks up the tab registered as "UsersDynTab" in the DynTabRegistry.

      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 uniqueIdentifier already 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 @TabScoped CDI 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 user
      includePage - the path to the XHTML page to render in the tab
      uniqueIdentifier - the unique ID for duplicate detection
      closeable - whether the user can close the tab
      cdiBeanClass - the CDI bean class associated with the tab
      parameters - the tab parameters map (can be null)
    • getMatchingTab

      public DynTab getMatchingTab(DynTab compareTab)
      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

      public DynTab getMatchingTab(String uniqueIdentifier)
    • isActiveTabWithUniqueID

      public boolean isActiveTabWithUniqueID(String uniqueIdentifier)
    • getFirstTabWithIncludePage

      public DynTab getFirstTabWithIncludePage(String includePage)
      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

      public void addOrSelectTab(DynTab tab)
    • fireApplicationEvent

      public void fireApplicationEvent(ApplicationCDIEvent event)
      Manually dispatches an ApplicationCDIEvent to all active tab beans. Same principle as fireDynTabEvent(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 CDI eventPublisher.fire() because @Observes does not work with @TabScoped beans.

    • addTab

      public void addTab(DynTab tabToAdd)
    • addTabListener

      protected void addTabListener(DynTab tabToAdd)
      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

      public List<DynTab> getActiveTabList()
    • removeCurrentTab

      public void removeCurrentTab(boolean ignorePendingChanges)