+ Start a Discussion
kjpetersonkjpeterson 

Can you set the tabStyle at runtime?

I want to set the tabstyle everytime a page is requested.  Is there any way to achieve this?  I tried this but I got an error that {!TabStyle} is an invalid tabstyle.

 

 

<apex:page sidebar="false" controller="customController" tabStyle="{!TabStyle}" >

 

 

 

RonHess.ax193RonHess.ax193
No, this is not settable using an expression.  You must use a simple string
kjpetersonkjpeterson
So there's no way to set it dynamically?  I has to be statically set in the text of the visual force page?
kjpetersonkjpeterson
I'll describe what I'm trying to do as well and maybe someone can think of a different approach.  I want a visualforce page that multiple Web Tabs can link to (WebTab1, WebTab2).  If someone clicks WebTab1 then I want WebTab1 to be selected when the visualforce page loads.  If someone clicks WebTab2, which links to the same visualforce page, then I want WebTab2 to be selected.  I can hardcode WebTab1 to be the tabstyle in the visualforce page but then WebTab2 won't highlight correctly.  If I don't set a tabstyle in the visualforce page then the Home tab shows as selected.
Ron HessRon Hess

there are two things going on when you set tab style on the apex : page component

 

one is the body class="leadTab" CSS specifier.

 

this you could probably fool around with and set using javascript.

 

However the other thing that occurs is the correct Tab is marked with the following style 

 

 

<td class="currentTab primaryPalette" nowrap="nowrap"> <div> <a title="Leads Tab - Selected" href="/00Q/o">Leads</a> </div> </td>

 

 This cuases it to highlight the correct tab, setting this dynamicaly using javascript is very hard and basically hacking the DOM, not a supported method or interface.

 

So, you cannot set tabStyle at runtime.

 

 

To do what you describe , simply create a single Visualforce Component , and then have multiple  Visualforce pages which all specify their own tabStyle, and include this component as their sole contents.

 

 

now you have a seperate tabStyle on each, but they leverage common content from the component.

 

 

 

trmptrmp