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
kamal24kamal24 

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>
Best Answer chosen by kamal24
Raj VakatiRaj Vakati
Use this code
 
<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" action="{!getResult}" reRender="Details"/>
                    </apex:selectList>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
            <apex:outputPanel id="Details">            
                
                <!--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:outputPanel>
        </apex:pageBlock>
    </apex:form>
</apex:page>
 
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--'));
        getResult();
    }
    
    public void getResult(){
        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;
        }
    }
}

 

All Answers

Raj VakatiRaj Vakati
Use this code
 
<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" action="{!getResult}" reRender="Details"/>
                    </apex:selectList>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
            <apex:outputPanel id="Details">            
                
                <!--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:outputPanel>
        </apex:pageBlock>
    </apex:form>
</apex:page>
 
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--'));
        getResult();
    }
    
    public void getResult(){
        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;
        }
    }
}

 
This was selected as the best answer
kamal24kamal24
Yes it worked.
Thank you Raj
 
Raj VakatiRaj Vakati
cool! mark it as solved!