+ Start a Discussion
learning1.3953795511514497E12learning1.3953795511514497E12 

How to rerender a cusotm component through command button?

Hi,

I have a custom component to display the pageblock table. I want to call it  through a button. When I click on the button then only the compnent should be called , but here it is calling before clicking on the button.

VF Code :
---------------------------

<apex:page standardController="Account" extensions="ArchivedRecordsInPageBlockTable" sidebar="False">
  
    <apex:form id="thefrm">   
        <apex:commandButton value="Display data" action="{!buttonCode}" rerender="ArchivedTableID"/>
       
    </apex:form>  
   
<apex:outputPanel id="callComponent">
    <c:DynamicObjectTable ObjectName="Case"  id="callComponent"
       FieldsetName="Test" DetailFields="DetailFieldsSet"    
       JSONData="{!jsonData}"
       Title="Archived Cases"
       TablePageSize="10"
    />  
   </apex:outputPanel>
    </apex:page>

Controller :
--------------------

public with sharing class ArchivedRecordsInPageBlockTable
{
public String jsonData {get;set;}

    public ArchivedRecordsInPageBlockTable(ApexPages.StandardController controller)
    {
           // fetchArchivedCasesCallout();
   
    }   
    private void fetchArchivedCasesCallout()
    {
       jsonData = '[{"LastReferencedDate": "", "SuppliedCompany": "", "Priority": "Medium", "OwnerId": "0059000000252PUAAY", "Type": "Electrical", "Status": "Closed", "CaseNumber": 85501, "ClosedDate": "2014-03-07T05:18:18.000Z", "IsEscalated": "false", "LastModifiedDate": "2014-03-07T05:18:18.000Z", "SuppliedPhone": "", "ContactId": "", "Reason": "Performance", "CreatedById": "0059000000252PUAAY", "LastViewedDate": "", "IsDeleted": "false", "SuppliedName": "", "SuppliedEmail": "", "LastModifiedById": "0059000000252PUAAY", "ParentId": "", "Description": "", "Origin": "Phone", "IsClosed": "true", "SystemModstamp": "2014-03-07T05:18:18.000Z", "CreatedDate": "2014-03-07T05:18:18.000Z", "AccountId": "", "Id": "5009000000JXKu7AAH", "Subject": "Power generation below stated level"},{"LastReferencedDate": "", "SuppliedCompany": "", "Priority": "Medium", "OwnerId": "0059000000252PUAAY", "Type": "Electrical", "Status": "Closed", "CaseNumber": 85501, "ClosedDate": "2014-03-07T05:18:18.000Z", "IsEscalated": "false", "LastModifiedDate": "2014-03-07T05:18:18.000Z", "SuppliedPhone": "", "ContactId": "", "Reason": "Performance", "CreatedById": "0059000000252PUAAY", "LastViewedDate": "", "IsDeleted": "false", "SuppliedName": "", "SuppliedEmail": "", "LastModifiedById": "0059000000252PUAAY", "ParentId": "", "Description": "", "Origin": "Phone", "IsClosed": "true", "SystemModstamp": "2014-03-07T05:18:18.000Z", "CreatedDate": "2014-03-07T05:18:18.000Z", "AccountId": "", "Id": "5009000000JXKu7AAH", "Subject": "Power generation below stated level"},{"LastReferencedDate": "", "SuppliedCompany": "", "Priority": "Medium", "OwnerId": "0059000000252PUAAY", "Type": "Electrical", "Status": "Closed", "CaseNumber": 85501, "ClosedDate": "2014-03-07T05:18:18.000Z", "IsEscalated": "false", "LastModifiedDate": "2014-03-07T05:18:18.000Z", "SuppliedPhone": "", "ContactId": "", "Reason": "Performance", "CreatedById": "0059000000252PUAAY", "LastViewedDate": "", "IsDeleted": "false", "SuppliedName": "", "SuppliedEmail": "", "LastModifiedById": "0059000000252PUAAY", "ParentId": "", "Description": "", "Origin": "Phone", "IsClosed": "true", "SystemModstamp": "2014-03-07T05:18:18.000Z", "CreatedDate": "2014-03-07T05:18:18.000Z", "AccountId": "", "Id": "5009000000JXKu7AAH", "Subject": "Power generation below stated level"},{"LastReferencedDate": "", "SuppliedCompany": "", "Priority": "Medium", "OwnerId": "0059000000252PUAAY", "Type": "Electrical", "Status": "Closed", "CaseNumber": 85501, "ClosedDate": "2014-03-07T05:18:18.000Z", "IsEscalated": "false", "LastModifiedDate": "2014-03-07T05:18:18.000Z", "SuppliedPhone": "", "ContactId": "", "Reason": "Performance", "CreatedById": "0059000000252PUAAY", "LastViewedDate": "", "IsDeleted": "false", "SuppliedName": "", "SuppliedEmail": "", "LastModifiedById": "0059000000252PUAAY", "ParentId": "", "Description": "", "Origin": "Phone", "IsClosed": "true", "SystemModstamp": "2014-03-07T05:18:18.000Z", "CreatedDate": "2014-03-07T05:18:18.000Z", "AccountId": "", "Id": "5009000000JXKu7AAH", "Subject": "Power generation below stated level"}]';         
            
    }   
   
    public void buttonCode()
    {
      //
    }
             
   
}

If " fetchArchivedCasesCallout() " is un commented from the constructor it directly calls the custom component. but i dnt want to call it directly .
I want to call it through the command button

Sonam_SFDCSonam_SFDC
In the vf page where you have defined the button:
<apex:commandButton value="Display data" action="{!buttonCode}" rerender="ArchivedTableID"/>

the rerender ID should be of the output panel which you wish you refresh..right? and that will be  the component id ="callComponent" if I've understood the code correctly..pls correct me if I'm wrong
learning1.3953795511514497E12learning1.3953795511514497E12
Hi, yes, you are correct. The code i have given there is wrong. the actual VF Page which is not working is as below....