primefaces - tabview 的事件索引未自动更新

标签 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>

示例 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>

我需要识别“onChange”事件上的单元格。但 activeIndex 始终为 0,即初始化值。事件没有得到调用。

bean
private Integer activeTabIndex = 0;
public Integer getActiveTabIndex() {
   return activeTabIndex;
}
public void setActiveTabIndex(Integer activeTabIndex) {
    this.activeTabIndex = activeTabIndex;
}

bean
public void tabChanged(TabChangeEvent event){
        TabView tv = (TabView) event.getComponent(); 
        this.activeTabIndex = tv.getActiveIndex();
    }

但该事件并没有被触发。也不会自动更新。

可能的问题是什么?

谢谢,
什哈

最佳答案

当标签未包含在形式内时,这适用于我,但每个选项卡都包含自己的选项卡:

  • 向 tabView 组件添加一个用于选项卡更改事件的监听器:

  • 从底层 TabView 组件获取事件索引似乎不起作用。但是,在事件中,新选择的选项卡已正确更新,因此我们可以通过在 TabView 的子组件中搜索来获取索引:

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


    我希望这对你也有用

    关于primefaces - tabview 的事件索引未自动更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9913930/

    相关文章:

    jsf - 如何在不影响Primefaces中的输出标签的情况下将inputText设置为必填?

    javascript - primefaces上传后如何重新加载jsf页面?

    jsf-2 - primefaces p :ajax update not working

    android - 使用TabLayout和ViewPager时,应用程序在选项卡2的后退按钮上崩溃

    ios - SwiftUI 中的双向无限 PageView

    jsf-2 - Primefaces 3.2 客户端 API 文档在哪里?

    android - 我希望能够在 Android TabView 中左右滑动以在选项卡之间切换

    keyboard - 当键盘出现在 SwiftUI 中时 OnAppear 意外调用

    对话框内选项卡布局中的Android ListView 无法显示滚动条

    jsf-2 - 如何在primefaces中使用RequestContext?