How to switch from one tab to another when button is clicked in apex:tabPanel?

Sample Code:

Visualforce page:


<apex:page controller="Sample">
<apex:form >
    <apex:tabPanel id="theTabPanel" value="{!tabOpt}">
        <apex:tab label="One" name="One" id="One"><apex:commandButton value="Go to Two" action="{!switch}"/></apex:tab>
        <apex:tab label="Two" name="Two" id="Two">content for tab two</apex:tab>
    </apex:tabPanel>
</apex:form>   
</apex:page>

Apex Controller:

public class Sample
{
    public String tabOpt {get;set;}
    public String amount {get;set;}
    public Boolean curencyBool {get;set;}
   
    public sample()
    {           
    }     
   
    public void switch()
    {
        tabOpt = 'Two';
    }
}

2 comments:

  1. For more than 2 tabs ?

    ReplyDelete
    Replies
    1. Give unique names for the tabs. In this example, I had used just 2 tabs.

      Delete