Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I have one VF page that I'd like to use for multiple tabs depending on some logic in the controller. Is there any way to set tabStyle dynamically? I've tried both of the following, and neither one works:

Attempt #1

<apex:page ... tabStyle="{!IF(some_logic_is_true,'TabA__tab','TabB__tab')}" ... >

Attempt #2

/* in the controller */
public String getTabStyle () {
    if (some_logic_is_true) {
        return 'TabA__tab';
    }
    return 'TabB__tab';
}

 

<!-- the VF Page -->
<apex:page ... tabStyle="{!tabStyle}" ... >

Result: Both of these approaches resulted in the following error:

Save error: Invalid tabStyle '{!tabStyle}' specified.  If you are trying to reference
a custom Visualforce tab, you must append '__tab'.

Any other ideas out there?

share|improve this question
add comment

2 Answers 2

up vote 5 down vote accepted

There is no way to set the tabstyle dynamically. You can vote for the idea here.

You will have to create a separate (empty) visualforce page for each of the tabs that you want to be selected and either include your real page:

<apex:page id="thePage" tabstyle="TabA__tab">
    <apex:include pageName="realpage"/>
</apex:page>

Or turn your page into a visualforce component and include it that way.

share|improve this answer
add comment

I can't find a way of how to customize 'tabStyle' in Page, but you can try to use 'tabStyle' in the apex:pageBlock, see,

http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_pageBlock.htm

VF page,

<apex:page controller="page_tabStyle" showHeader="true" sidebar="false"  >
  <apex:pageBlock title="Hello {!$User.FirstName}!" tabStyle="{!IF($CurrentPage.Parameters.render == 'Account', 'Account', 'Contact')}"  >
        This is your new page for the {!name} controller. <br/>
        You are viewing the {!account.name} account.
  </apex:pageBlock>
</apex:page>

Controller, `public class page_tabStyle {

public String getName() { return 'MyController'; } public Account getAccount() { return [select id, name from Account where id = :ApexPages.currentPage().getParameters().get('id')]; }

}`

When you call like, https://xxx.c.cs6.visual.force.com/apex/page_tabStyle?id=001N0000003BOTu&render=Account

you got the style of Account,

https://xxx.c.cs6.visual.force.com/apex/page_tabStyle?id=001N0000003BOTu&render=Contact

you got the style of Contact.

share|improve this answer
    
It seems you can't call Controller method directly in tabStyle, so you have to determine how to communicate on the VF page. –  Jia Hu Jan 22 '13 at 2:01
    
Nice, but per the docs, this only controles "the color scheme of the page block", and the key issue for me is which tab appears to be selected in the tab bar. –  Benj Jan 22 '13 at 2:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.