Active tab not preserved

Components, Ajax Framework, Utilities and More.
Post Reply
primefaceshack
Posts: 21
Joined: 07 Aug 2011, 17:46

24 Sep 2011, 00:23

I have a page with three tabs (tab1, tab2, tab3) and each tab I have a datatable that contains a hyperlink on the first column. If I am on tab2 and click the hyperlink, it takes me to a different page containing a back hyperlink. When I click on the back hyperlink, it goes back to the previous page but the active tab is not 'tab2', it is default to 'tab1'. Can someone please tell me how to code to make the active tab is 'tab2'.

I am using PF 3.0-M3.

Thanks in advance.

primefaceshack
Posts: 21
Joined: 07 Aug 2011, 17:46

25 Sep 2011, 17:18

Anyone, please?

kukeltje
Expert Member
Posts: 8469
Joined: 17 Jun 2010, 13:34
Location: Netherlands

25 Sep 2011, 23:57

You asked this on saturday and expect an answer on sunday... It IS weekend you know... Patience is a virtue
Ronald van Kuijk
______________________________
PrimeFaces 5.2, PrimeFaces plus 0.0.2 | JbossWildfly 8.1| Mojarra 2.2.8
Fedora 21, Firefox 'most recent'
Read the forum posting rules
Beginners: https://jsf.zeef.com/bauke.scholtz

bubi
Posts: 19
Joined: 21 Oct 2010, 07:51

07 Feb 2013, 16:47

To preserve the Tab Index between several Updates use the activeIndex attribute for the TabView component to set the activeTab. To save the active Tab use a <p:ajax> element for the event 'tabChange'

Code: Select all

<p:tabView activeIndex="#{bean.activeIndex}">
        <p:ajax event="tabChange" listener="#{bean.onTabChange}" />
...
</p:tabView>
and a Listener Method in your Bean which sets the property with the proper value:

Code: Select all

private int activeIndex; // +setter/getter

public void onTabChange(TabChangeEvent event) {
        Tab activeTab = event.getTab();
        TabView parent=(TabView)activeTab.getParent();
        activeIndex=parent.getActiveIndex();
}
primefaces 6.1 +++ myfaces 2.2.12 +++ weld 2.4.3 +++ tomcat 8.5.14 +++ java se 1.8.0_121-b13 +++ mac os x 10.12.4

User avatar
andyba
Expert Member
Posts: 2475
Joined: 31 Mar 2011, 16:27
Location: Steinfeld, near Bremen/Osnabrück, DE
Contact:

07 Feb 2013, 17:21

@Bubi: have you read the Forum rules recently? There is at least one which says, and I am paraphrasing here,
Thou shalt not dig up very old Threads and play with them because they smell of corpses and Andyba has a very sensitive nose
PF 4.x (Elite versions), PF 5, Pf 5.1, PF 6.0
Glassfish 4.1, Mojarra 2.x, Java 8, Payara 4.1.1.
If you haven't read the forum rules read them now

kukeltje
Expert Member
Posts: 8469
Joined: 17 Jun 2010, 13:34
Location: Netherlands

07 Feb 2013, 18:18

ROTFLOL
Ronald van Kuijk
______________________________
PrimeFaces 5.2, PrimeFaces plus 0.0.2 | JbossWildfly 8.1| Mojarra 2.2.8
Fedora 21, Firefox 'most recent'
Read the forum posting rules
Beginners: https://jsf.zeef.com/bauke.scholtz

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 5 guests