Board index JavaServer Faces General Active tab not preserved

Active tab not preserved

Components, Ajax Framework, Utilities and More.

Post 24 Sep 2011, 00:23

Posts: 18
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.

Post 25 Sep 2011, 17:18

Posts: 18
Anyone, please?

Post 25 Sep 2011, 23:57
kukeltje Expert Member

Posts: 6483
Location: Netherlands
You asked this on saturday and expect an answer on sunday... It IS weekend you know... Patience is a virtue
Ronald van Kuijk
______________________________
PrimeFaces 4.0, PrimeFaces plus 0.0.2 | Jboss 7.2.0 | Mojarra 2.1.18
Fedora 19, Firefox 26.0
Read the forum posting rules
Beginners: http://www.coreservlets.com/JSF-Tutorial/jsf2/

Post 07 Feb 2013, 16:47

Posts: 19
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'
<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:
private int activeIndex; // +setter/getter

public void onTabChange(TabChangeEvent event) {
        Tab activeTab = event.getTab();
        TabView parent=(TabView)activeTab.getParent();
        activeIndex=parent.getActiveIndex();
}
primefaces 3.5 +++ myfaces 2.1.13 +++ weld 2.1. +++ tomcat 7.0.47 +++ java se 7.0_45 +++ mac os x 10.9

Post 07 Feb 2013, 17:21
andyba User avatar
Expert Member

Posts: 2210
Location: Steinfeld, near Bremen/Osnabrück, DE

@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 3.4.2, PF 3.5.10, PF 4.x (Elite versions)
Glassfish 3.1.2.2, Mojarra 2.x, under both Java 6 and Java 7.
If you haven't read the forum rules read them now
My blog: http://onthefaceofthings.blogspot.de/
PrimeFaces Project

Post 07 Feb 2013, 18:18
kukeltje Expert Member

Posts: 6483
Location: Netherlands
ROTFLOL
Ronald van Kuijk
______________________________
PrimeFaces 4.0, PrimeFaces plus 0.0.2 | Jboss 7.2.0 | Mojarra 2.1.18
Fedora 19, Firefox 26.0
Read the forum posting rules
Beginners: http://www.coreservlets.com/JSF-Tutorial/jsf2/


Return to General