【问题标题】:Primefaces tabview: set Active Index after some countingPrimefaces tabview:在一些计数后设置活动索引
【发布时间】:2013-08-14 16:16:45
【问题描述】:

我有一个选项卡视图,其中包含四个选项卡和三个命令按钮(计数、添加到表、导出到 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>

支持豆 公共 int getActiveTabIndex() { 返回活动标签索引; }

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);
}

但这对我不起作用,您有什么想法:我如何在计数后设置第三个选项卡 activeIndex=2?

【问题讨论】:

  • 您的 id="count" 命令按钮未绑定到任何支持 bean 函数。您可以将其绑定到设置 activeTabIndex 的支持 bean 函数。
  • 您必须更新tabChange 上的整个标签视图,以便在视图中更新活动标签。
  • 当你点击按钮时会发生什么?您的 BackingBean 的范围是什么?尝试在 setActiveTabIndex 方法中记录 activeIndex 值。
  • 您的代码似乎是多余的:为什么需要将活动索引设置为已活动选项卡的索引?

标签: java jsf primefaces


【解决方案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) {}
}


如果我正确理解您的意图。

【讨论】:

    猜你喜欢
    • 2013-05-11
    • 2011-09-24
    • 2015-01-06
    • 2012-04-12
    • 1970-01-01
    • 2013-09-08
    • 1970-01-01
    • 2019-11-17
    • 1970-01-01
    相关资源
    最近更新 更多