+ Start a Discussion
Prateek Jain 52Prateek Jain 52 

Not able to clear List Upon onchange event on apex:PageBlocktable.

Requirement:
Hi all, I have a requirement where i have two table and based 
of the selection of record of one table i need to display 
its corresponding chid record.

Problem:
"
I have Written onchange event on checkbox, On action i calling one method and fecthing the child record of selected record and storing inList,
" But Problem is everytime upon onchange i am not able to clear the list so that it will show the selected record ite in child table.

Please see the sample code as below:

Vf page code :

    <apex:pageBlockTable value="{!CategoryList}" var="cl" style="width:100%" rows="3" id="blocktable1" >
           <apex:column headerValue="Select" colspan="20" width="10%">
           <apex:inputCheckbox style="height:auto;width:auto;"  value="{!cl.Main_Category__c}" html-data-cbType="mainContactCheckbox">
           <apex:actionSupport event="onchange"  action="{!ExpensesListMethod}" onSubmit="checkboxChanged(this)" reRender="outputpanel2">
            <apex:param name="CategoryId" value="{!cl.Id}" assignTo="{!categoryId}"/>    
                   </apex:actionSupport>    
                    </apex:inputCheckbox>
                    </apex:column>
          </apex:pageBlockTable>

Apex Class code : 

public class ExpensesCombo {
        
    public List<Category__c> CategoryList {get; set;}
    public List<Expenses_Card__c> ExpensesList {get; set;}
    public List<Expenses_Detail__c> ExpensesDetailList {get; set;}
    public Id categoryId {get; set;}
    public Boolean Maincategory {get; set;}

    public Id expensesCardId {get; set;}
        
    public ExpensesCombo(){
        CategoryList = [Select id, name, Address__c,Main_Category__c from Category__c];
        

         ExpensesList = new List<Expenses_Card__c>(); 
         ExpensesList.clear();
                      
    }
    
//Method which is causing the problem and not clearing the list values.
    public void ExpensesListMethod(){
    system.debug('Value for categoryId is22: ' +categoryId);
     system.debug('Value for mainCategory2 ' +Maincategory );
            
//trying clearing the List here
            if (ExpensesList!=null || !ExpensesList.ISEmpty()){
            System.debug('insideList');
            ExpensesList= new List<Expenses_Card__c>();
            ExpensesList.clear();
            }
    
    // trying creating the new instance for fresh values
    ExpensesList= new List<Expenses_Card__c>();
 
    ExpensesList = [Select id, name, Total_Amount_Paid__c, Balance_Due__c, Description__c, Account_Number__c from Expenses_Card__c 
                        where Category__c = :categoryId order by Balance_Due__c desc];    
                        
                        System.debug('CheckList1111' + ExpensesList  );    
                        
                      }
}

Note: Main problem is not able to clear List Upon onchange event on apex:PageBlocktable.

Need Help Badly on this, please let me know what i am exactly missing here., thanks



 
V V Satyanarayana MaddipatiV V Satyanarayana Maddipati
Hi Prateek Jain,

Try to reRender the pageblocktable, on change of the checkbox as shown below :
<apex:actionSupport event="onchange" action="{!ExpensesListMethod}" onSubmit="checkboxChanged(this)" reRender="outputpanel2,blocktable1">

Thanks
Satya.