tabview的Active Index未自动更新

Shi*_*wan 9 primefaces tabview

Active Index未自动更新.通过将tabView放在可以使用的表单上来回顾一些帖子.或者通过<p:ajax event="tabChange"/>在tabview中包含它是有效的.但似乎没有任何效果

XHTML

示例1:自动更新

    <p:tabView id="categoryTabView" var="promoArticle" value="#{promotionDetailBean.artDTOs}"  activeIndex="#{promotionDetailBean.activeTabIndex}">
            <p:tab id="categoriesTab" title="#{promoArticle.categoryName}">
                <p:dataTable id="promotionDetail_dataTable" var="articlePromo" value="#{promoArticle.artVO}" selection="#{promotionDetailBean.selectedArt}" rowIndexVar="rowIndex">
                    <p:column id="select" selectionMode="multiple" />

                    <p:column id="barCode">
                        <h:inputText id="barCodeInputTxt" value="#{articlePromo.barCode}"
                        styleClass="inputTextStyle" onchange="onSuggestedValueChange('categoryTabView',#{promotionDetailBean.activeTabIndex}, 'promotionDetail_dataTable',#{rowIndex},'originalCostInputTxt')" />
                    </p:column>
                </p:dataTable>
            </p:tab>
        </p:tabView>
Run Code Online (Sandbox Code Playgroud)

示例2:更新tabChange事件

  <h:form id="form">
    <p:growl id="growlm" showDetail="true" />  

            <p:tabView id="categoryTabView" var="promoArticle" value="#{promotionDetailBean.artDTOs}"  >
               <p:ajax event="tabChange" listener="#{promotionDetailBean.tabChanged}"  update=":growlm" />
                    <p:tab id="categoriesTab" title="#{promoArticle.categoryName}">
                        <p:dataTable id="promotionDetail_dataTable" var="articlePromo" value="#{promoArticle.artVO}" selection="#{promotionDetailBean.selectedArt}" rowIndexVar="rowIndex">
                            <p:column id="select" selectionMode="multiple" />

                            <p:column id="barCode">
                                <h:inputText id="barCodeInputTxt" value="#{articlePromo.barCode}"
                                styleClass="inputTextStyle" onchange="onSuggestedValueChange('categoryTabView',#{promotionDetailBean.activeTabIndex}, 'promotionDetail_dataTable',#{rowIndex},'originalCostInputTxt')" />
                            </p:column>
                        </p:dataTable>
                    </p:tab>
                </p:tabView>
Run Code Online (Sandbox Code Playgroud)

我需要在"onChange"事件中识别单元格.但activeIndex始终为0,即初始值.该活动未接到电话.

private Integer activeTabIndex = 0;
public Integer getActiveTabIndex() {
   return activeTabIndex;
}
public void setActiveTabIndex(Integer activeTabIndex) {
    this.activeTabIndex = activeTabIndex;
}
Run Code Online (Sandbox Code Playgroud)

public void tabChanged(TabChangeEvent event){
        TabView tv = (TabView) event.getComponent(); 
        this.activeTabIndex = tv.getActiveIndex();
    }
Run Code Online (Sandbox Code Playgroud)

但事件并没有得到发展.也不会自动更新.

可能的问题是什么?

谢谢,Shikha

小智 13

当选项卡不包含在表单中但每个选项卡包含自己的选项卡时,这适用于我:

  1. 将标签更改事件的监听器添加到tabView组件:

    <p:ajax event="tabChange" listener="#{userBean.onTabChange}" />
  2. 从基础TabView组件获取活动索引似乎不起作用.但是,在这种情况下,新选择的选项卡会正确更新,因此我们可以通过搜索TabView的子组件来获取索引:

    public void onTabChange(TabChangeEvent event) 
    {   
        TabView tabView = (TabView) event.getComponent();
        activeTab = tabView.getChildren().indexOf(event.getTab());
    }

我希望这也适合你


Shi*_*wan 6

以下对我有用:

XHTML:

<p:tabView id="categoryTabView" var="promoArticle"
        value="#{promotionDetailManagedBean.articuloPromocionDTOs}" dynamic="true">
    <p:ajax event="tabChange" listener="#{promotionDetailManagedBean.onTabChange}" />
    <p:tab> ... </p:tab>
</p:tabView>
Run Code Online (Sandbox Code Playgroud)

豆:

public final void onTabChange(final TabChangeEvent event) {
    TabView tv = (TabView) event.getComponent();
    this.activeTabIndex = tv.getActiveIndex();
}
Run Code Online (Sandbox Code Playgroud)

  • 仅在[活动索引未绑定到托管bean上]的情况下,这才行得通(http://code.google.com/p/primefaces/issues/detail?id=1640&amp;q=activeIndex&amp;colspec=ID%20Stars%20Module%20Type% 20Status%20Priority%20TargetVersion%20Reporter%20Owner%20Summary)。我很惊讶Primefaces团队尚未解决它(我正在使用3.5版本)。但是,如果将`tabView`本身包装成表单而不是为每个标签都具有一个表单,则它起作用。 (2认同)
  • this.activeTabIndex = tv.getActiveIndex(); 不起作用.相反,你可以使用this.activeTabIndex = tv.getChildren().indexOf(event.getTab()); (2认同)