Reputation: 93
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());
}
Upvotes: 3
Views: 193
Reputation: 20188
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:
Upvotes: 3