3

How can i keep active tab after i get redirected from anoter site? On my interface i would like to return information on a tab window after a user has done credit card authorization using a third party service.

I have frontend done by Primefaces.

Tab view on 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>

My backinBean:

  private Integer activeTab = 0;

  public Integer getActiveTab() {
    return activeTab;
  }

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

reports.xhtml contains a button which directs user to credit card authorization service. After the authorization the user gets redirected back to my site, where information should be displayed on the same tab, which has the button for auth service. Information is displayed correctly, but client doesn't keep the tab active. How to achieve this?

Tested solution from this question didn't work. After redirect page shows the first tab on index.xhtml

index.xhtml tabs

    <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());
  }
Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
WScoder
  • 93
  • 1
  • 8
  • Does this answer your question? [Active Index of tabview not getting updated automatically](https://stackoverflow.com/questions/9913930/active-index-of-tabview-not-getting-updated-automatically) – Jasper de Vries Mar 29 '21 at 07:50
  • No. I tried using the ajax component, but that also shows the first tab on the site after redirect from auth service. – WScoder Mar 29 '21 at 08:15
  • There must be an error in what you've tried. Please update the question with what you've tried. – Jasper de Vries Mar 29 '21 at 08:17
  • Added tested solution according to link posted by [Active Index of tabview not getting updated automatically](https://stackoverflow.com/questions/9913930/active-index-of-tabview-not-getting-updated-automatically) – WScoder Mar 29 '21 at 09:12

1 Answers1

3

Almost there. You should not have removed activeIndex="#{backinBean.activeTab}" from your p:tabView. Also, there is a typo in your EL. You should not use getActiveTab to get activeTab, simply use activeTab.

Also, in this case, the scope of your bean should be set to @SessionScoped.

See also:

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102