【问题标题】:How to keep p:tabView tab active after roundtrip to external site如何在往返外部站点后保持 p:tabView 选项卡处于活动状态
【发布时间】:2021-03-29 07:39:00
【问题描述】:

从另一个站点重定向后,如何保持活动标签? 在我的界面上,我想在用户使用第三方服务完成信用卡授权后在选项卡窗口上返回信息。

我的前端由 Primefaces 完成。

xhtml 上的选项卡视图:

    <p:tabView id="mytabs" styleClass="mystyle" style="min-height: 600px;" activeIndex="#{backinBean.getActiveTab}">
      <p:tab title="tab" titleStyleClass="mystyle">
        <ui:include src="reports.xhtml"/>
      </p:tab>
    </p:tabView>
  </p:tab>
  <p:tab id="anothertab" title="Another tab" titleStyleClass="myclass"
    <ui:include src="2ndtab.xhtml"/>
  </p:tab>
</p:tabView>

我的backinBean:

  private Integer activeTab = 0;

  public Integer getActiveTab() {
    return activeTab;
  }

  public void setActiveTab(Integer activeTab) {
    this.activeTab = activeTab;
  }

reports.xhtml 包含一个将用户引导至信用卡授权服务的按钮。 授权后,用户被重定向回我的站点,信息应显示在同一选项卡上,该选项卡具有身份验证服务按钮。信息显示正确,但客户端不保持选项卡处于活动状态。如何做到这一点?

来自 question 的测试解决方案不起作用。重定向页面显示 index.xhtml 上的第一个选项卡后

index.xhtml 选项卡

    <p:tabView id="mytabs" styleClass="mystyle" style="min-height: 600px;">
 <p:ajax event="tabChange" listener="#{backinBean.onTabChange}" />
      <p:tab title="tab" titleStyleClass="mystyle">
        <ui:include src="firstTab"/>
      </p:tab>
    </p:tabView>
  </p:tab>
  <p:tab id="wantedActiveTab" title="Another tab" titleStyleClass="myclass"
    <ui:include src="2ndtab.xhtml"/>
  </p:tab>
</p:tabView>

backinBean:

private Integer activeTab = 0;

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

【问题讨论】:

标签: jsf primefaces


【解决方案1】:

差不多了。您不应该从您的p:tabView 中删除activeIndex="#{backinBean.activeTab}"。此外,您的 EL 中有一个错字。您不应该使用getActiveTab 来获取activeTab,只需使用activeTab

此外,在这种情况下,您的 bean 的范围应设置为 @SessionScoped

另见:

【讨论】:

    猜你喜欢
    • 2018-04-08
    • 1970-01-01
    • 2021-11-17
    • 1970-01-01
    • 2018-11-18
    • 2023-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多