function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Brendan LallyBrendan Lally 

How to return to specify sub Tab layout within Tabbed Accounts example

In http://wiki.apexdevnet.com/index.php/Tabbed_Accounts_in_30_seconds
I've done the same for my custom object and it works pretty good.
On mine I have defined  TAB-A, TAB-B, TAB-C
I have extension controller code getting called on one of my extra Tabs (TAB-B) and that works fine too.

However I want it to return the user exactly where they were (in TAB-B) but I cannot find what that tab reference/url is.
It appears to be a Frame with a hidden field (j_id0:CaseTabPanel=TAB-B)

Any ideas on how I'd re-render that back from my controller (via PageReference ?)

Thanks
Lal
Best Answer chosen by Admin (Salesforce Developers) 
NatePoloNatePolo

Hi Saravanan,

Thank you for posting the sample code. Please forgive my ignorance on this but, I still don't think my question has been answered. I believe the post (and your sample code) shows how to get the value of the "{!SelectedTab}" from the controller. However, none of the examples clearly show how to set the value of the selected tab. 

 

Shouldn't there be a javascript event or something that happens when a user clicks on a tab?

I expect to see some apex code with reference to a javascript that sets the value in the URL so that when the user navigates back to the page, the controller can read it and set the "{!SelectedTab}" value. 

 

In comment #11 (http://community.salesforce.com/sforce/board/message?board.id=Visualforce&view=by_date_ascending&message.id=4660#M4660) there's some javascript there, but I still don't see a browser event that triggers the setting of the value. 

 

Obviously, I'm missing something here. Could someone please point it out to me?

 

Thank you.

Message Edited by NatePolo on 08-04-2009 05:41 AM

All Answers

dchasmandchasman
You'll want to look at using a value binding instead of a constant for the selectedTab attribute in your tabPanel:

<apex:tabPanel switchType="client" selectedTab="{!theSelectedTab}" id="theTabPanel">

then in your controller action you can set the value of theSelectedTab property and when the rerender happens the correct tab should be selected.
Brendan LallyBrendan Lally
Doug,
Thanks for that .
what is the format of my PageRef (I presume 2 invoke the proper tab)
I did have the following

Ta
Code:
  return new PageReference( '/apex/cases_inner_tabs—id=' + listing_id );

 

Brendan LallyBrendan Lally
and the id of my tab is called   id="listingsTab"
dchasmandchasman
The tabs are not separate pages and has nothing to to with PageReferences. The id you use is simply the value from <apex:tab id>, listingsTab in your case.
Brendan LallyBrendan Lally
Doug,

So how do I do that (if its not a PageRef)
i.e. "..then in your controller action you can set the value of theSelectedTab property and when the rerender happens the correct tab should be selected."       2 get my listingsTab  selected
?

ta
jwetzlerjwetzler
Well, in theory all you would need to do is:
Code:
public class TabExt {

    public TabExt(ApexPages.StandardController controller) {

    }
    
    public String getSelectedTabName() {
//put any special logic in here about which tab to return
return 'Contacts'; } }

<apex:tabPanel switchType="client" selectedTab="{!SelectedTabName}" id="theTabPanel">

 and selectedTab refers to the name attribute of your tab.

The bad news, this does not appear to be working with formulas, meaning it needs a String like "Contacts" instead of being able to call into a property on your controller.  I'll log a bug for this for my team.

dchasmandchasman
Jill is correct - **bleep** - even after you wire it up with correct tabName values the formula is not evaluating correctly - we'll get this fixed.
Brendan LallyBrendan Lally
thanks guys..

How do I know when this gets fixed?

Does it come with the next major release or do u roll little bug-fixes into prod (I'm in DE and TE editions at moment - about 2 go 2 beta) without us really seeing it?

Is there a way to track this issue (msg id 3659) and I presume this gets tagged to your internal bug tracking system (which I presume we have no visibility into)

Lal
Brendan LallyBrendan Lally
ok, been dealing with trying 2 get this working 4 last few weeks and no joy (in my code)
...so I created some example code per your example and exampled from Tabbed Accounts

It displays fine - shows tabs and data etc.. but when I set the 'tab to return to' in the extension controller (can see it getting set ok via a debug statement and also in a pageblock display) it does NOT RETURN to the correct tab.

Help - what am I missing...

Here's the code

Code:
<apex:page standardController="Account" showHeader="true" tabStyle="account" extensions="accounts_extn" >
   <style>
      .activeTab {background-color: #236FBD; color:white; background-image:none}
      .inactiveTab { background-color: lightgrey; color:black; background-image:none}
   </style>


   <apex:tabPanel switchType="client" selectedTab="{!SelectedTabName}" id="AccountTabPanel" tabClass="activeTab" inactiveTabClass="inactiveTab">   
      <apex:tab label="Details" name="AccDetails" id="tabdetails">
         <apex:pageblock> SelectedTabName="{!SelectedTabName}" </apex:pageblock>
         <apex:detail relatedList="false" title="true"/>
      </apex:tab>

      <apex:tab label="Contacts" name="Contacts" id="tabContact">
         <apex:relatedList subject="{!account}" list="contacts" />
      </apex:tab>

      <apex:tab label="Opportunities" name="Opportunities" id="tabOpp">
         <apex:relatedList subject="{!account}" list="opportunities" />
      </apex:tab>

      <apex:tab label="Open Activities" name="OpenActivities" id="tabOpenAct">
         <apex:relatedList subject="{!account}" list="OpenActivities" />
      </apex:tab>

      <apex:tab label="Notes and Attachments" name="NotesAndAttachments" id="tabNoteAtt">
         <apex:relatedList subject="{!account}" list="NotesAndAttachments" />
      </apex:tab>

   </apex:tabPanel>

</apex:page>

------------------------------------------------

public class accounts_extn 
{
// test from tabbedAccounts  Apex front-end to test http://wiki.apexdevnet.com/index.php/Tabbed_Accounts_in_30_seconds  via  controller extension

    public Accounts_extn( ApexPages.StandardController controller )
    {
       System.debug('In extension controller   accounts_extn. About to return with tabOpp');
    }

 
    public String getSelectedTabName() 
    {
      //put any special logic in here about which tab to return
       return 'tabOpp';
    }

}

and debug output
Code:
20:09:24 DEBUG - ***Begining Page Log for /apex/tabbedAccounts
20080826020919.944:Class.illumia.accounts_extn.<init>: line 7, column 8: In extension controller   accounts_extn. About to return with tabOpp
20080826020919.944:External entry point:     returning from end of method public accounts_extn<Constructor>(ApexPages.StandardController) in 0 ms
20080826020919.944:External entry point:     returning String from method public String getSelectedTabName() in 0 ms
Cumulative profiling information:

No profiling information for SOQL operations.

No profiling information for SOSL operations.

No profiling information for DML operations.

2 most expensive method invocations:
Class.illumia.accounts_extn: line 5, column 12: public accounts_extn<Constructor>(ApexPages.StandardController): executed 1 time in 0 ms
Class.illumia.accounts_extn: line 11, column 19: public String getSelectedTabName(): executed 1 time in 0 ms

***Ending Page Log for /apex/tabbedAccounts—id=0017000000Pc509

 


 Thanks in advance.... stumped!!

Lal

Mark YoungMark Young
This isn't idea, but if you're desparate the following javascript (or similar) works.  Place it after your tabPanel on your page (after customising for main tabPanel id):
 
Code:
    <script>
     if ('{!$CurrentPage.parameters.currentTab}' != '')
     {
      if (RichFaces && RichFaces.panelTabs['{!$Component.mainTabs}'])
      {
       var tabs = RichFaces.panelTabs['{!$Component.mainTabs}'];
       for (var i = 0; i < tabs.length; i++)
       {
        if (tabs[i].name == '{!$CurrentPage.parameters.currentTab}')
        {
         RichFaces.switchTab('{!$Component.mainTabs}', tabs[i].id, tabs[i].name);
         break;
        }
       }
      }
     }
    </script>

 
As always, this is dangerous as Salesforce functions could change at any time.
 
 
Call it as /apex/tabpage?currentTab=tabName
 
Mark
 
 


Message Edited by Mark Young on 08-25-2008 10:08 PM
hamayoun65hamayoun65
Hi

Is there a timeframe for when this will be fixed?
NatePoloNatePolo

The question that never seems to get answered in this thread is "how do you set the {!theSelectedTab} value?"

Looking at the code, I don't see anything that describes how to fire off the method in the controller that sets the value.

 

I want to be able to set the value when a user click on a tab and then re-read that value when the page loads so that the user's tab session never loses state. 

JavajJavaj

here is the answer with sample code:

 

 

Code:
public class Tabs {
public String SelectedTab { get; set; }
}

Code:
<apex:page controller="Tabs" >
<apex:tabPanel switchType="Ajax" value="{!SelectedTab}">
<apex:tab label="Tab1" name="Name1" />
<apex:tab label="Tab2" name="Name2" />
<apex:tab label="Tab3" name="Name3" />
<apex:tab label="Tab4" name="Name4" />
</apex:tabPanel>
{!SelectedTab}
</apex:page>
NatePoloNatePolo

Hi Saravanan,

Thank you for posting the sample code. Please forgive my ignorance on this but, I still don't think my question has been answered. I believe the post (and your sample code) shows how to get the value of the "{!SelectedTab}" from the controller. However, none of the examples clearly show how to set the value of the selected tab. 

 

Shouldn't there be a javascript event or something that happens when a user clicks on a tab?

I expect to see some apex code with reference to a javascript that sets the value in the URL so that when the user navigates back to the page, the controller can read it and set the "{!SelectedTab}" value. 

 

In comment #11 (http://community.salesforce.com/sforce/board/message?board.id=Visualforce&view=by_date_ascending&message.id=4660#M4660) there's some javascript there, but I still don't see a browser event that triggers the setting of the value. 

 

Obviously, I'm missing something here. Could someone please point it out to me?

 

Thank you.

Message Edited by NatePolo on 08-04-2009 05:41 AM
This was selected as the best answer