有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Primefaces选项卡视图:在计数后设置活动索引

我有一个选项卡视图,其中包含四个选项卡和三个命令按钮(计数、添加到表格、导出到Word)

我在第一个选项卡中输入一些文本数据,在第二个选项卡中输入一些数字数据,然后当我按下第一个命令按钮(计数)时,我的程序进行一些计数,但我不能在第三个选项卡上设置活动索引,在第三个选项卡上显示计数结果

<h:form id="dataForm1" prependId="false">
   <div>
      <p:commandButton id="count" update="tbv" process="tbv:tab1 tbv:tab2" />
      <p:commandButton id="addToWord" .... />
      <p:commandButton id="exportToWord" ... />
   </div
   <div>
      <p:growl id="growlm" showDetail="true" /> 
    <p:tabView activeIndex="#{disableTag.activeTabIndex}" id="tbv" tabChangeListener="#{disableTag.onTabChange}">
        <p:ajax event="tabChange" listener="#{disableTag.onTabChange}" update=":dataForm1:growlm" />
          <p:tab id="tab1">some text data </p:tab>
          <p:tab id="tab2">some numeric data</p:tab>
          <p:tab id="tab3">result of counting from tab2</p:tab>
          <p:tab id="tab4">table</p:tab>
     </p:tabView>

背豆 public int getActiveTabIndex(){ 返回activeTabIndex; }

public void setActiveTabIndex(int activeTabIndex) {
    this.activeTabIndex = activeTabIndex;
}

public void onTabChange(TabChangeEvent event) {
    TabView tv = (TabView) event.getComponent();
    this.setActiveTabIndex(tv.getActiveIndex());
    System.out.println("###### ACtive tab: "+activeTabIndex);
}

但它对我不起作用,你有什么想法吗:如何在计数后设置第三个tab activeIndex=2


共 (1) 个答案

  1. # 1 楼答案

    这是一种获得它的方法:

    //查看

        <h:form id="yourForm">
            ...
            <p:commandButton value="Go to tab 3" action="#{yourBackingBean.doSomeCounting('2')}"
                             update="tabView"/>
            ...
        </h:form>
    


    然后在你的计算方法中:

    //BackingBean

    public void doSomeCounting(String tabIndex){
        // your counting logic
        try {
            activeTabIndex = Integer.parseInt(tabIndex);
            System.out.println("showing tab: "+activeTabIndex);
        } catch (NumberFormatException e) {}
    }
    


    如果我正确理解你的意图