You need to sign in to do that
Don't have an account?
kamal24
how can we use <selectlist> with wrapper class to change pageBlockTable by changing <selectoption> ?
My code is:-
Controller extension:
public class wrapController {
public String typeValue{get;set;}
public List<SelectOption> typeOptions{get;set;}
public List<wrapAccount> wrapaccts{get;set;}
public wrapController(ApexPages.StandardController stdController){
typeOptions = new List<SelectOption>();
typeOptions.add(new SelectOption('None','--None--'));
Schema.DescribeFieldResult fieldResult = Account.Type.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistvalues();
for(Schema.PicklistEntry p : ple){
typeOptions.add(new SelectOption(p.getvalue(), p.getvalue()));
}
wrapaccts=new List<wrapAccount>();
List<Account> accList = new List<Account>([SELECT Name, Phone, AccountNumber, Type FROM Account WHERE Type = :typeValue]);
for(Account acc :accList){
wrapaccts.add(new wrapAccount(acc));
}
}
public class wrapAccount{
public Boolean checkbox{get;set;}
public Account ac{get;set;}
public wrapAccount(Account a){
this.ac=a;
checkbox=false;
}
}
}
Page:
<apex:page standardController="Account" extensions="wrapController" id="pg">
<apex:form id="fm">
<apex:pageBlock title="Account Info" id="Account_List">
<apex:pageBlockSection title="Accounts" id="pbs">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Account Type:"/>
<apex:selectList value="{!typeValue}" size="1">
<apex:selectOptions value="{!typeOptions}"/>
<apex:actionSupport event="onchange" reRender="fm"/>
</apex:selectList>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<!--Account_List-->
<apex:pageBlockTable value="{!wrapaccts}" var="wr" id="pbt">
<apex:column headerValue="Select" > <apex:inputCheckbox id="cb"/> </apex:column>
<apex:column value="{!wr.ac.Name}" headerValue="Account Name"/>
<apex:column value="{!wr.ac.Phone}" headerValue="Phone Number"/>
<apex:column value="{!wr.ac.AccountNumber}" headerValue="Account Number"/>
<apex:column value="{!wr.ac.Type}" headerValue="Account Type"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller extension:
public class wrapController {
public String typeValue{get;set;}
public List<SelectOption> typeOptions{get;set;}
public List<wrapAccount> wrapaccts{get;set;}
public wrapController(ApexPages.StandardController stdController){
typeOptions = new List<SelectOption>();
typeOptions.add(new SelectOption('None','--None--'));
Schema.DescribeFieldResult fieldResult = Account.Type.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistvalues();
for(Schema.PicklistEntry p : ple){
typeOptions.add(new SelectOption(p.getvalue(), p.getvalue()));
}
wrapaccts=new List<wrapAccount>();
List<Account> accList = new List<Account>([SELECT Name, Phone, AccountNumber, Type FROM Account WHERE Type = :typeValue]);
for(Account acc :accList){
wrapaccts.add(new wrapAccount(acc));
}
}
public class wrapAccount{
public Boolean checkbox{get;set;}
public Account ac{get;set;}
public wrapAccount(Account a){
this.ac=a;
checkbox=false;
}
}
}
Page:
<apex:page standardController="Account" extensions="wrapController" id="pg">
<apex:form id="fm">
<apex:pageBlock title="Account Info" id="Account_List">
<apex:pageBlockSection title="Accounts" id="pbs">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Account Type:"/>
<apex:selectList value="{!typeValue}" size="1">
<apex:selectOptions value="{!typeOptions}"/>
<apex:actionSupport event="onchange" reRender="fm"/>
</apex:selectList>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<!--Account_List-->
<apex:pageBlockTable value="{!wrapaccts}" var="wr" id="pbt">
<apex:column headerValue="Select" > <apex:inputCheckbox id="cb"/> </apex:column>
<apex:column value="{!wr.ac.Name}" headerValue="Account Name"/>
<apex:column value="{!wr.ac.Phone}" headerValue="Phone Number"/>
<apex:column value="{!wr.ac.AccountNumber}" headerValue="Account Number"/>
<apex:column value="{!wr.ac.Type}" headerValue="Account Type"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
All Answers
Thank you Raj