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
Ashu sharma 38Ashu sharma 38 

Tab panel functionality

I want two tab on that when i click on contact it shows records related to contact whatever i search on input text.
now i click on Account tab ,account list records should be displyed when i search something on input.


public  class Searchname {
    
    public String name            {get;set;}
    public list<contact> myCon    {get;set;}
    public list<Account> myAcc    {set;get;}
    public boolean searched       {get;set;}
    public boolean flagForAccount  {get;set;}
    public boolean flagForContact  {set;get;}
    
    public searchname() {
        flagForAccount=true;
        flagForContact=true;
        searched=false;
        string namestr=ApexPages.currentPage().getParameters().get('name');
        if(null!=namestr) {
            name=namestr;
        }
    }
    public PageReference executeSearch() {
        searched=true;
        flagForAccount=false;
        flagForContact=true; 
        System.debug('name' +name);
        string searchstr=('%'+name+'%');
        System.debug(searchstr);
        myCon=[select id,lastName,firstName from contact where name Like:searchstr limit 10];
        System.debug(myCon);
        return null;
    }
    
    public void showAccountPanel(){
        flagForAccount=true;
        flagForContact=false;
        
      }
    
    public PageReference executeSearchForAccount() {
        searched=true;
        flagForAccount=true;
        flagForContact=false; 
        System.debug('name' +name);
        string searchstr=('%'+name+'%');
        System.debug(searchstr);
        myAcc=[select id,name,rating from account where name Like:searchstr limit 10];
        System.debug(myCon);
       return null;
    }
}
=======
Vf page
<apex:page controller="Searchname" showHeader="false">
    <apex:form >
        <!--    <apex:actionFunction name="someMet" action="" />
--> 
        <apex:tabPanel id="ObjectPanel">
            <apex:tab label="Contact" name="nameCons" id="con" />
            <apex:tab label="Account" name="nameAcc" id="acc" onclick="nameAcc()"/>   
        </apex:tabPanel>
        <apex:actionFunction action="{!showAccountPanel}" name="nameAcc" reRender="acc"/>
        <apex:PageBlock>
            <!-- Contact Section.. -->
            <apex:PageBlockSection id="con" >
                <apex:PageBlockSectionItem >
                    <apex:outputLabel >Name</apex:outputLabel>
                    <apex:inputText value="{!name}"/>
                </apex:PageBlockSectionItem>
                <apex:commandButton value="Search Contact" action="{!executeSearch}"/>
                
                <apex:PageBlockTable var="act" value="{!myCon}" id="con"> 
                    <apex:column value="{!act.lastName}" />  
                    <apex:column value="{!act.firstName}"/>
                </apex:PageBlockTable>
            </apex:PageBlockSection>
        </apex:PageBlock>
            <apex:pageBlock>
           
              <!-- Account Section..   --> 
            <apex:pageBlockSection  id="acc" rendered="{!flagForAccount}">
                <apex:pageBlockSectionItem>
                    <apex:outputLabel>Account Name</apex:outputLabel>
                    <apex:inputText value="{!name}"/>
                </apex:pageBlockSectionItem>
                <apex:commandButton value="Search Account"  action="{!executeSearchForAccount}" reRender="acc"/>
            </apex:pageBlockSection>
            <apex:pageBlockTable var="acc" value="{!myAcc}">
                <apex:column value="{!acc.name}"/>
                <apex:column value="{!acc.rating}"/>
            </apex:pageBlockTable>
                </apex:pageBlock>
        
    </apex:form>
</apex:page>



 
Best Answer chosen by Ashu sharma 38
Parmanand PathakParmanand Pathak
Hi Satish,

I have modified the code as per your requirement  using Vf component - 

Apex Class -  
public  class Searchname {
    
    public String name            {get;set;}
    public list<contact> myCon    {get;set;}
    public list<Account> myAcc    {set;get;}
    public boolean searched       {get;set;}
    public boolean flagForAccount  {get;set;}
    public boolean flagForContact  {set;get;}
    
    public searchname() {
        flagForAccount=true;
        flagForContact=true;
        searched=false;
        string namestr=ApexPages.currentPage().getParameters().get('name');
        if(null!=namestr) {
            name=namestr;
        }
    }
    public PageReference executeSearch() {
        searched=true;
        flagForAccount=false;
        flagForContact=true; 
        System.debug('name' +name);
        string searchstr=('%'+name+'%');
        System.debug(searchstr);
        myCon=[select id,lastName,firstName from contact where name Like:searchstr limit 10];
        System.debug(myCon);
        return null;
    }
    
    public void showAccountPanel(){
        flagForAccount=true;
        flagForContact=false;
        
      }
    
    public PageReference executeSearchForAccount() {
        searched=true;
        flagForAccount=true;
        flagForContact=false; 
        System.debug('name' +name);
        string searchstr=('%'+name+'%');
        System.debug(searchstr);
        myAcc=[select id,name,rating from account where name Like:searchstr limit 10];
        System.debug(myCon);
       return null;
    }
}

Vf Component - (DisplayAcTab ) - 
<apex:component controller="Searchname">
              <apex:pageBlock id="accdisplay">
            <apex:pageBlockSection id="acc" rendered="{!flagForAccount}">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel >Account Name</apex:outputLabel>
                    <apex:inputText value="{!name}"/>
                </apex:pageBlockSectionItem>
                <apex:commandButton value="Search Account"  action="{!executeSearchForAccount}" reRender="accdisplay"/>
            </apex:pageBlockSection>
            <apex:pageBlockTable var="acc" value="{!myAcc}">
                <apex:column value="{!acc.name}"/>
                <apex:column value="{!acc.rating}"/>
            </apex:pageBlockTable>
                </apex:pageBlock>
</apex:component>
Vf Component - (DisplayConTab) - 
<apex:component controller="Searchname">
   
                <apex:actionFunction action="{!showAccountPanel}" name="nameAcc" reRender="condisplay"/>
        <apex:PageBlock id="condisplay">
            <!-- Contact Section.. -->
            <apex:PageBlockSection id="con" >
                <apex:PageBlockSectionItem >
                    <apex:outputLabel >Name</apex:outputLabel>
                    <apex:inputText value="{!name}"/>
                </apex:PageBlockSectionItem>
                <apex:commandButton value="Search Contact" action="{!executeSearch}"/>
                
                <apex:PageBlockTable var="act" value="{!myCon}" id="con"> 
                    <apex:column value="{!act.lastName}" />  
                    <apex:column value="{!act.firstName}"/>
                </apex:PageBlockTable>
            </apex:PageBlockSection>
        </apex:PageBlock>
           
</apex:component>

Create Vf Page and Call both the component with the tabPanel - 
<apex:page controller="Searchname" showHeader="false">
      
        <apex:form>
        <apex:tabPanel id="ObjectPanel">
            <apex:tab label="Contact" name="nameCons" id="con1" >
               <c:DisplayAcTab />
            </apex:tab>
            
             <apex:tab label="Account" name="nameAcc" id="acc1" >
               <DisplayConTab />
         </apex:tab>   
         </apex:tabPanel> 
         </apex:form> 
</apex:page>



Mark it as best answer to help the community if it helps you.

Thanks,
Parmanand Pathak




 

All Answers

Parmanand PathakParmanand Pathak
Hi Saitsh,

Try below code - 

Apex Class-
public  class Searchname {
    
    public String name            {get;set;}
    public list<contact> myCon    {get;set;}
    public list<Account> myAcc    {set;get;}
    public boolean searched       {get;set;}
    public boolean flagForAccount  {get;set;}
    public boolean flagForContact  {set;get;}
    
    public searchname() {
        flagForAccount=true;
        flagForContact=true;
        searched=false;
        string namestr=ApexPages.currentPage().getParameters().get('name');
        if(null!=namestr) {
            name=namestr;
        }
    }
    public PageReference executeSearch() {
        searched=true;
        flagForAccount=false;
        flagForContact=true; 
        System.debug('name' +name);
        string searchstr=('%'+name+'%');
        System.debug(searchstr);
        myCon=[select id,lastName,firstName from contact where name Like:searchstr limit 10];
        System.debug(myCon);
        return null;
    }
    
    public void showAccountPanel(){
        flagForAccount=true;
        flagForContact=false;
        
      }
    
    public PageReference executeSearchForAccount() {
        searched=true;
        flagForAccount=true;
        flagForContact=false; 
        System.debug('name' +name);
        string searchstr=('%'+name+'%');
        System.debug(searchstr);
        myAcc=[select id,name,rating from account where name Like:searchstr limit 10];
        System.debug(myCon);
       return null;
    }
}
VF Page - 
 
<apex:page controller="Searchname" showHeader="false">
    <apex:form >
        <apex:tabPanel id="ObjectPanel">
            <apex:tab label="Contact" name="nameCons" id="con1" >
                <apex:actionFunction action="{!showAccountPanel}" name="nameAcc" reRender="condisplay"/>
        <apex:PageBlock id="condisplay">
            <!-- Contact Section.. -->
            <apex:PageBlockSection id="con" >
                <apex:PageBlockSectionItem >
                    <apex:outputLabel >Name</apex:outputLabel>
                    <apex:inputText value="{!name}"/>
                </apex:PageBlockSectionItem>
                <apex:commandButton value="Search Contact" action="{!executeSearch}"/>
                
                <apex:PageBlockTable var="act" value="{!myCon}" id="con"> 
                    <apex:column value="{!act.lastName}" />  
                    <apex:column value="{!act.firstName}"/>
                </apex:PageBlockTable>
            </apex:PageBlockSection>
        </apex:PageBlock>
            </apex:tab>
            
            
             <apex:tab label="Account" name="nameAcc" id="acc1" >
              <!-- Account Section..   --> 
              <apex:pageBlock id="accdisplay">
            <apex:pageBlockSection id="acc" rendered="{!flagForAccount}">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel >Account Name</apex:outputLabel>
                    <apex:inputText value="{!name}"/>
                </apex:pageBlockSectionItem>
                <apex:commandButton value="Search Account"  action="{!executeSearchForAccount}" reRender="accdisplay"/>
            </apex:pageBlockSection>
            <apex:pageBlockTable var="acc" value="{!myAcc}">
                <apex:column value="{!acc.name}"/>
                <apex:column value="{!acc.rating}"/>
            </apex:pageBlockTable>
                </apex:pageBlock>
         </apex:tab>   
         </apex:tabPanel> 
    </apex:form>
</apex:page>

Thanks,
Parmanand Pathak

 
Ashu sharma 38Ashu sharma 38
Hi Parmanand Pathak
Thank you,
Could you please explain how to achive this same one usie to make vf component..
Parmanand PathakParmanand Pathak
Hi Satish,

I have modified the code as per your requirement  using Vf component - 

Apex Class -  
public  class Searchname {
    
    public String name            {get;set;}
    public list<contact> myCon    {get;set;}
    public list<Account> myAcc    {set;get;}
    public boolean searched       {get;set;}
    public boolean flagForAccount  {get;set;}
    public boolean flagForContact  {set;get;}
    
    public searchname() {
        flagForAccount=true;
        flagForContact=true;
        searched=false;
        string namestr=ApexPages.currentPage().getParameters().get('name');
        if(null!=namestr) {
            name=namestr;
        }
    }
    public PageReference executeSearch() {
        searched=true;
        flagForAccount=false;
        flagForContact=true; 
        System.debug('name' +name);
        string searchstr=('%'+name+'%');
        System.debug(searchstr);
        myCon=[select id,lastName,firstName from contact where name Like:searchstr limit 10];
        System.debug(myCon);
        return null;
    }
    
    public void showAccountPanel(){
        flagForAccount=true;
        flagForContact=false;
        
      }
    
    public PageReference executeSearchForAccount() {
        searched=true;
        flagForAccount=true;
        flagForContact=false; 
        System.debug('name' +name);
        string searchstr=('%'+name+'%');
        System.debug(searchstr);
        myAcc=[select id,name,rating from account where name Like:searchstr limit 10];
        System.debug(myCon);
       return null;
    }
}

Vf Component - (DisplayAcTab ) - 
<apex:component controller="Searchname">
              <apex:pageBlock id="accdisplay">
            <apex:pageBlockSection id="acc" rendered="{!flagForAccount}">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel >Account Name</apex:outputLabel>
                    <apex:inputText value="{!name}"/>
                </apex:pageBlockSectionItem>
                <apex:commandButton value="Search Account"  action="{!executeSearchForAccount}" reRender="accdisplay"/>
            </apex:pageBlockSection>
            <apex:pageBlockTable var="acc" value="{!myAcc}">
                <apex:column value="{!acc.name}"/>
                <apex:column value="{!acc.rating}"/>
            </apex:pageBlockTable>
                </apex:pageBlock>
</apex:component>
Vf Component - (DisplayConTab) - 
<apex:component controller="Searchname">
   
                <apex:actionFunction action="{!showAccountPanel}" name="nameAcc" reRender="condisplay"/>
        <apex:PageBlock id="condisplay">
            <!-- Contact Section.. -->
            <apex:PageBlockSection id="con" >
                <apex:PageBlockSectionItem >
                    <apex:outputLabel >Name</apex:outputLabel>
                    <apex:inputText value="{!name}"/>
                </apex:PageBlockSectionItem>
                <apex:commandButton value="Search Contact" action="{!executeSearch}"/>
                
                <apex:PageBlockTable var="act" value="{!myCon}" id="con"> 
                    <apex:column value="{!act.lastName}" />  
                    <apex:column value="{!act.firstName}"/>
                </apex:PageBlockTable>
            </apex:PageBlockSection>
        </apex:PageBlock>
           
</apex:component>

Create Vf Page and Call both the component with the tabPanel - 
<apex:page controller="Searchname" showHeader="false">
      
        <apex:form>
        <apex:tabPanel id="ObjectPanel">
            <apex:tab label="Contact" name="nameCons" id="con1" >
               <c:DisplayAcTab />
            </apex:tab>
            
             <apex:tab label="Account" name="nameAcc" id="acc1" >
               <DisplayConTab />
         </apex:tab>   
         </apex:tabPanel> 
         </apex:form> 
</apex:page>



Mark it as best answer to help the community if it helps you.

Thanks,
Parmanand Pathak




 
This was selected as the best answer
Ashu sharma 38Ashu sharma 38
Hi Parmanand Pathak,

How it can be use by using different controller...I mean for component different controller..

 
Parmanand PathakParmanand Pathak
Hi Satish,

You can use different controllers . But if your requirement is fullfilled by only one controller then its good to go for only one class and call it to the different components.

Thanks,
Parmanand Pathak
Ashu sharma 38Ashu sharma 38
Hi Parmanand Pathak,

Just know how to make it using different controller i have example on google but now able to grab properly,would you elaborate on this above case.