Package dyntabs

Class DynTab

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

public class DynTab extends Object implements Serializable
Represents a single dynamic tab in the DynTabs framework.

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 the p:tab ID in the template
  • includePage - path to the XHTML page rendered inside this tab
  • uniqueIdentifier - used to detect duplicate tabs (prevents opening the same tab twice)
  • cdiBean - the @TabScoped CDI bean associated with this tab
  • parameters - 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 Details

    • DynTab

      public DynTab()
      Default constructor.
    • DynTab

      public DynTab(String id, String includePage)
  • Method Details

    • getCdiBeanClass

      public Class<?> getCdiBeanClass()
    • setCdiBeanClass

      public void setCdiBeanClass(Class<?> cdiBeanClass)
    • resolveCdiBean

      public void resolveCdiBean()
      Resolves the CDI bean instance from the CDI container using the stored cdiBeanClass.

      MUST be called AFTER TabScopedContextHolder.setCurrentTabId(String) has been set, because @TabScoped beans require an active tab context.

      If cdiBean is already set (e.g. manually via setCdiBean(dyntabs.interfaces.DyntabBeanInterface)), does nothing. If cdiBeanClass is not set, also does nothing (tab without a bean).

    • setCdiBean

      public void setCdiBean(DyntabBeanInterface cdiBean)
    • getCdiBean

      public DyntabBeanInterface getCdiBean()
      Returns the CDI bean associated with this tab.

      IMPORTANT: Before returning the bean (which is a proxy for @NormalScope), this method sets currentTabId to 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:forEach renders all tabs at once while currentTabId is 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

      public String getId()
    • setId

      public void setId(String id)
    • getName

      public String getName()
    • setName

      public void setName(String name)
    • isActive

      public boolean isActive()
      Returns whether this tab is currently active (visible on screen). Active tabs are displayed as p:tab components in the UI template.
      Returns:
      true if the tab is active and visible
    • setActive

      public void setActive(boolean isActive)
    • getTitle

      public String getTitle()
    • setTitle

      public void setTitle(String title)
    • getUniqueIdentifier

      public String getUniqueIdentifier()
    • setUniqueIdentifier

      public void setUniqueIdentifier(String uniqueIdentifier)
    • getIncludePage

      public String getIncludePage()
    • setIncludePage

      public void setIncludePage(String includePage)
    • setActivated

      public void setActivated(boolean activated)
    • isActivated

      public boolean isActivated()
    • setCloseable

      public void setCloseable(boolean isCloseable)
    • isCloseable

      public boolean isCloseable()
    • getInstance

      @Deprecated public static DynTab getInstance(String tabName)
      Deprecated.
      This method is tied to the old approach where tabs were registered as <managed-bean> in faces-config.xml. Since Jakarta EE 10+, managed beans are no longer supported. Use DynTabRegistry.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

      public void setParameters(Map parameters)
    • getParameters

      public Map getParameters()
    • isComponentVisibleByClientId

      public boolean isComponentVisibleByClientId(String key)
      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 true if a Boolean true value exists for that key, false otherwise.

      Parameters:
      key - the component's client ID (with colons replaced by underscores)
      Returns:
      true if the dialog should be visible
    • isComponentVisibleById

      public boolean isComponentVisibleById(String key)
      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

      public Map<String,Object> getDynTabVisibleMap()
    • getTabSubviewClientId

      public String 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 by getDynTabVisibleMap().
      Parameters:
      event - the PrimeFaces CloseEvent
    • closeDialog

      public void closeDialog(jakarta.faces.event.ActionEvent e)