You need to sign in to do that
Don't have an account?

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>
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>
I have modified the code as per your requirement using Vf component -
Apex Class -
Vf Component - (DisplayAcTab ) - Vf Component - (DisplayConTab) -
Create Vf Page and Call both the component with the tabPanel -
Mark it as best answer to help the community if it helps you.
Thanks,
Parmanand Pathak
All Answers
Try below code -
Apex Class- VF Page -
Thanks,
Parmanand Pathak
Thank you,
Could you please explain how to achive this same one usie to make vf component..
I have modified the code as per your requirement using Vf component -
Apex Class -
Vf Component - (DisplayAcTab ) - Vf Component - (DisplayConTab) -
Create Vf Page and Call both the component with the tabPanel -
Mark it as best answer to help the community if it helps you.
Thanks,
Parmanand Pathak
How it can be use by using different controller...I mean for component different controller..
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
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.