+ Start a Discussion
philbophilbo 

Navigating away from a VF page with a tabPanel - remember active tab?

OK, here's the thing:

 

We have a VF page consisting mostly of an <apex:tabPanel> containing several <apex:tab> components.  The contents of these tabs are somewhat complex and take a bit of time to build, so we don't want to ever re-render the tabPanel if we can help it.

 

Each tab contains controls that allow navigation away from this page (e.g. one contains a related list with the standard Edit/New controls). When we do so, and now we're on whatever other page, and we hit Save or Cancel, we are returned to our VF page as expected, and it is re-rendered at that time.  

 

Back on our VF page, though, we are now sitting on the page's default tab, as opposed to the tab we were on when we navigated away.  This is the problem I'm trying to solve.  I have envisioned the following approaches:

 

1) Inject the currently active tab (name or Id) into the current URL via a page parameter, whenever a tab is selected. 

 

I have not gotten this to work because I cannot modify the current URL without causing the whole page to re-render, and that is unacceptable because of load time.  I tried modifying the current URL both in the controller (via an actionFunction linked to the 'ontabenter' event of the tab - NOT by setting the tabPanel's 'switchType' attribute to 'ajax' or 'server', which also causes a page re-render), and via javascript, modifying 'window.location.search' directly, but neither allows me to sneak the parameter into the page without re-rendering it.  Which I suppose is to be expected.

 

2) Remember the currently active tab in a cookie.  Then, when the page is initialized (or re-initialized when we return to it), grab the cookie and use its value to set the active tab.  

 

If I could get the cookie value back into the controller as part of its initialization, then this would work easily, as I could then use it to set a controller property, and bind it to the tabPanel's 'value' attribute before the tabPanel gets rendered.  But I don't know of any way to do that.

 

Alternatively, I could conceivably use the cookie directly in Javascript to poke whatever information into the underlying HTML to 'spoof' a tab selection.  I did actually look into this, inspecting the HTML of a sample page, and I see style classes like 'dr-tbpnl-tbcell-inact' vs. 'dr-tbpnl-tbcell-act' that I could maybe toggle on the appropriate page components.  Or maybe there's some JS method that already exists, buried in main.js or somewhere, that could be leveraged?  Seems a little risky to me, reverse-engineering SF functionality - dodgy at best and non-forward-compatible at worst.

 

Anybody got any suggestions about this?  Remember, the key point here is to keep track of tab changes without re-rendering the tabPanel, in a way that survives navigating away from + back to the page.

 

Thanks!

 

Best Answer chosen by Admin (Salesforce Developers) 
SteveBowerSteveBower
I don't mean "Custom Settings" by the way, I mean a custom field on the User Object.

All Answers

SteveBowerSteveBower

Question: When people "navigate away from this page" via the controls, are they actually SFDC generated controls, or are they small VF pages where you've placed the Edit/New buttons and they call the standard controller functions.    The reason I ask is that if they are your controls, you could append a "retURL" parameter to the URLs that the user is navigating to.  In that retURL string you could append a tab number, or tab name, etc. to the return url and then your controller could pull it when it's used to return, and use it when re-rendering the tabs.

 

OR

 

(I assume this wouldn't work because it's ugly) could you navigate the user to a new tab in the Firefox sense of tab (or window)?  When they close that tab, the old one would be there unchanged.   That makes it a user training issue.  :-(

 

OR

 

Whenever your user navigates to a new tab you could update a User specific Setting for "CurrentTab"  Then when your controller reloads, just pull the Tab name/number/whatever from the Settings (which should be pretty fast)and use it to select the starting tab.  (This might be the best option?)

 

Best, Steve.

 

p.s. I think you could getJavascript cookies to work, however that's really not pretty.

SteveBowerSteveBower
I don't mean "Custom Settings" by the way, I mean a custom field on the User Object.
This was selected as the best answer
philbophilbo
Thanks very much Steve, I hadn't thought of option #3 - writing something into a custom field on the User object.  I implemented that and it works like a charm!
Devendra SawantDevendra Sawant

Hi Philbo,

 

I am facing same problem with <apex:tabpanel>.

 

Is it possible for you to post your code here? It would be ok if you post dummy code here. It would be helpful to solve this problem.

 

Cheers,

Devendra S