Search code examples
javajsficefaces

Tab selection problem in JSF icefaces


I have one tab set as below ,in which i want select dynamic tab using binding in java.

<ice:panelTabSet var="currentTab" partialSubmit="true"  selectedIndex="#{viewBatchBean.tabSelectedIndex}"
            value="#{viewBatchBean.batch.batchConfigurationTabList}"
            tabChangeListener="#{viewBatchBean.showDefaultValueForTab}"
            binding="#{viewBatchBean.panelTabSetRef}">

here i set tab index as below..

  panelTabSetRef.setSelectedIndex(0);

it set tab as per given index but doesn't set focus on it.


Solution

  • Populating the panelTabSetRef.

    //---
    
    for(SomeObject tabConfig : batchConfigurationTabList){
       PanelTab panelTab = new PanelTab();
       // Setting appropriate values in panelTab
       panelTabSetRef.getChildren().add(panelTab);
    }
    
    //---
    

    Fetching the PanelTab component from PanelTabSet & processing it accordingly.

    List<UIComponent> panelTabs= panelTabSetRef.getChildren();
    
    // Selecting tab to set focus
    
    PanelTab focusTab = (PanelTab) panelTabs.get(tabSelectedIndex);
    String tabId = focusTab.getId();
    
    //---
    

    Focus can be set on the selected tab as below using Java Script.

    JavascriptContext.addJavascriptCall(FacesContext.getCurrentInstance(), "someJSMethodToSetFocus('someForm:"+tabId+"');");
    

    Index out of bound exception is raised because the panel has not been populated & fetching children from it. Giving value directly as <ice:panelTabSet value="#{viewBatchBean.batch.batchConfigurationTabList}"/> populates when the the page is rendered accordingly. So manually populating the panelTabSetRef.

    In newer IceFaces version, tabIndex attribute has been added to panelTabSet.