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
G2WIntegrationG2WIntegration 

How to dynamically determine selectedTab

I was hoping to make <apex:tabPanel> behave nice and select one tab if the app hasn't been set up and the other if it has but ran into two problems:

1) Trying to set selectedTab to a dynamic value doesn't seem to work

2) Using value= doesn't work as then the user can't ever click on the other tab

 

Any tips I'm missing?  I hoped something like this would have worked:

<apex:page id="thePage" controller="controller">
    <apex:tabPanel switchType="client" selectedTab="{!selectedTab}" id="theTabPanel">
        <apex:tab label="One" name="name1" id="tabOne">content for tab one</apex:tab>
        <apex:tab label="Two" name="name2" id="tabTwo">content for tab two</apex:tab>
    </apex:tabPanel>
</apex:page>

And the apex class, where "schedulersActive" is set in another method.  This code works if using value="{!selectedTab}" but not for selectedTab as shown above.

public with sharing class controller{
	public String selectedTab{
		get{
			if (schedulersActive==TRUE)
				return 'name1';

			else
				return 'name2';
			
		}
		set;
	}//getSelectedTab
}

 

mast0rmast0r

HI, i think you have to return a tab NAME:

 

 

selectedTabObject

The name of the default selected tab when the page loads. This value must match the name attribute on a child tab component. If the value attribute is defined, the selectedTab attribute is ignored.

 

 

<apex:page id="thePage" controller="controller">
    <apex:tabPanel switchType="client" selectedTab="{!selectedTab}" id="theTabPanel">
        <apex:tab label="One" name="name1" id="tabOne">content for tab one</apex:tab>
        <apex:tab label="Two" name="name2" id="tabTwo">content for tab two</apex:tab>
    </apex:tabPanel>
</apex:page>

public String selectedTab{
    get{
        if (schedulersActive==TRUE)
	    return 'name1';
        else
	    return 'name2';		
    }
    set;
}
G2WIntegrationG2WIntegration

Thx - copy and paste issue as I copied the page from the doc and the controller from my code.  

 

The code does match the name in the controller to the page (and I've updated the post), but even with the name correct, it doesn't seem to work.  Any ideas?

aballardaballard

You can do this with the value attribute but need to incorporate a setter also to preserve the value selected by the user.  And your getter logic will have to take that into account.   Probably, initialize the property from the constructor , then the getter/setter just return either the initial value or whatever was subsequently set. 

 

G2WIntegrationG2WIntegration
Thanks! How do you return the selected value in the setter? I got hung up on that when first trying to use value="!{selectedTab}"