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
nbeekmannbeekman 

Tab, How do pass back to your controller

Hello,

 

I am working on developing a tabbed page in Visualforce but would like to know which tab the user is viewing.  If there is a way to determine this, I can cut a lot of code and buttons from the page view.

 

Anyone have a suggestion or a fast code example?

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
Sgt_KillerSgt_Killer

Try modifying your <apex:tabPanel> tag as shown below :-

 

<apex:tabPanel switchType="Ajax" value="{!selectedTab}" id="theTabPanel" activeTabClass="activeTab" inactiveTabClass="inactiveTab"
height="300%" headerSpacing="5">

All Answers

Sgt_KillerSgt_Killer

Try this out -)

 

Controller:

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

 

VF:

 

<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>

 

nbeekmannbeekman

Thanks for the response.  How does it push back the tab name that it's currently on?  My system.debug('>>>>>>>>> Tab is ' + selectedTab); keeps telling me the value is null no matter if its on load or when clicking a tab.

 

Sgt_KillerSgt_Killer

Did you specify the name attribut on <apex:tab> tag?? If not include the name attribute values in each <apex:tab> tag and the selectedTab will return the name value, thereby identifying the selected tab.

nbeekmannbeekman

Yes, I believe so, here is the code. 

 

<apex:page controller="BillBatchWrapper" showHeader="true" tabStyle="Opportunity" >
	<apex:pageBlock title="Welcome to Envysion Bill Batch">
		<h1>Instructions:  </h1>
		<p></p><h1>{!$User.FirstName} </h1>please select which Bill Batch Opportunities to bill then click the appropriate <h1>Process</h1> to complete.
	</apex:pageBlock>

	<apex:form >
		<apex:pageBlock title="Bill Batch Selection"> 
			<apex:pageBlockButtons >
				<apex:commandButton action="{!ProcessBillBatch1}" value="Process Bill Batch 1"/>
				<apex:commandButton action="{!ProcessBillBatch2}" value="Process Bill Batch 2"/>
				<apex:commandButton action="{!ProcessBillBatch3}" value="Process Bill Batch 3"/>
			</apex:pageBlockButtons>

			<style>
				.activeTab {background-color: #236FBD; color:white; background-image:none}
		    	.inactiveTab { background-color: lightgrey; color:black; background-image:none}
			</style>

			<apex:tabPanel switchType="Ajax" selectedTab="{!selectedTab}" id="theTabPanel" tabClass="activeTab" inactiveTabClass="inactiveTab"
				height="300%" headerSpacing="5">
				<apex:tab label="Bill Batch 1 List" name="BillBatch1" id="tab1">
					<apex:outputPanel >
						{!IF( OR(prevSizeBB1 > 0, currentSizeBB1 > 0), prevSizeBB1 + 1, 0)} to {!prevSizeBB1 + currentSizeBB1} 
							of {!prevSizeBB1 + currentSizeBB1 + nextSizeBB1} for Bill Batch 1
					</apex:outputPanel>
					<apex:actionStatus >
						<apex:facet name="start">Loading...</apex:facet> 
						<apex:facet name="stop"> 
						<apex:pageBlockTable value="{!recordsToDisplayBB1}" var="r">
							<apex:column value="{!r.Name}"></apex:column>
							<apex:column value="{!r.Job_ID__c}"></apex:column>
							<apex:column value="{!r.Type}"></apex:column>
							<apex:column value="{!r.TopMgmtFlag__c}"></apex:column>
							<apex:column value="{!r.Term_1__c}"></apex:column>
							<apex:column value="{!r.Bill_Start_Date__c}"></apex:column>
							<apex:column value="{!r.Bill_Batch_Date__c}"></apex:column>
							<apex:column value="{!r.Billing_Batch__c}"></apex:column>
							<apex:column value="{!r.Build_Status__c}"></apex:column>
						</apex:pageBlockTable>
						</apex:facet>
					</apex:actionStatus>
					<apex:outputText rendered="{!IF(currentSizeBB1 > 0,false,true)}" value="No Records to Display..."></apex:outputText>
				</apex:tab>

				<apex:tab label="Bill Batch 2 List" name="BillBatch2" id="tab2">
					<apex:outputPanel >
						{!IF( OR(prevSizeBB2 > 0, currentSizeBB2 > 0), prevSizeBB2 + 1, 0)} to {!prevSizeBB2 + currentSizeBB2} 
							of {!prevSizeBB2 + currentSizeBB2 + nextSizeBB2} for Bill Batch 2
					</apex:outputPanel>
					<apex:actionStatus >
						<apex:facet name="start">Loading...</apex:facet> 
						<apex:facet name="stop"> 
						<apex:pageBlockTable value="{!recordsToDisplayBB2}" var="r">
							<apex:column value="{!r.Name}"></apex:column>
							<apex:column value="{!r.Job_ID__c}"></apex:column>
							<apex:column value="{!r.Type}"></apex:column>
							<apex:column value="{!r.TopMgmtFlag__c}"></apex:column>
							<apex:column value="{!r.Term_1__c}"></apex:column>
							<apex:column value="{!r.Bill_Start_Date__c}"></apex:column>
							<apex:column value="{!r.Bill_Batch_Date__c}"></apex:column>
							<apex:column value="{!r.Billing_Batch__c}"></apex:column>
							<apex:column value="{!r.Build_Status__c}"></apex:column>
						</apex:pageBlockTable>
						</apex:facet>
					</apex:actionStatus>
					<apex:outputText rendered="{!IF(currentSizeBB2 > 0,false,true)}" value="No Records to Display..."></apex:outputText>
				</apex:tab>

				<apex:tab label="Bill Batch 3 List" name="BillBatch3" id="tab3">
					<apex:outputPanel >
						{!IF( OR(prevSizeBB3 > 0, currentSizeBB3 > 0), prevSizeBB3 + 1, 0)} to {!prevSizeBB3 + currentSizeBB3} 
							of {!prevSizeBB3 + currentSizeBB3 + nextSizeBB3} for Bill Batch 3
					</apex:outputPanel>
					<apex:actionStatus >
						<apex:facet name="start">Loading...</apex:facet> 
						<apex:facet name="stop"> 
						<apex:pageBlockTable value="{!recordsToDisplayBB3}" var="r">
							<apex:column value="{!r.Name}"></apex:column>
							<apex:column value="{!r.Job_ID__c}"></apex:column>
							<apex:column value="{!r.Type}"></apex:column>
							<apex:column value="{!r.TopMgmtFlag__c}"></apex:column>
							<apex:column value="{!r.Term_1__c}"></apex:column>
							<apex:column value="{!r.Bill_Start_Date__c}"></apex:column>
							<apex:column value="{!r.Bill_Batch_Date__c}"></apex:column>
							<apex:column value="{!r.Billing_Batch__c}"></apex:column>
							<apex:column value="{!r.Build_Status__c}"></apex:column>
						</apex:pageBlockTable>
						</apex:facet>
					</apex:actionStatus>
					<apex:outputText rendered="{!IF(currentSizeBB3 > 0,false,true)}" value="No Records to Display..."></apex:outputText>
				</apex:tab>
			</apex:tabPanel>
			{!SelectedTab}
		</apex:pageBlock>
	</apex:form>
</apex:page>

 

 

Controller has this embeded at the beginning.

 

public with sharing class BillBatchWrapper { 

	public string selectedTab { get; set; }	
	public Opportunity temp_opp { get; set;}
	public Boolean checked{ get; set; }

 

What am I doing wrong?

Sgt_KillerSgt_Killer

Try modifying your <apex:tabPanel> tag as shown below :-

 

<apex:tabPanel switchType="Ajax" value="{!selectedTab}" id="theTabPanel" activeTabClass="activeTab" inactiveTabClass="inactiveTab"
height="300%" headerSpacing="5">

This was selected as the best answer
nbeekmannbeekman

This worked, the only issue is for anyone reviewing is that you need to set the value initially as it will be null the first time the page opens. I set it to a default only if null will fix it.

 

thanks again.