[SalesForce] how to reRender tab label

I have a tabPanel with some tabs, and same tabs have a number (counter) ex. Accounts(2), I want to reRender the label of account tab to update the number of accounts when I add new account.
I used the following code, but when I click on Add button, tab content disappear and nothing change.

Controller

public Integer AccountsNo {set; get;}
public list<Account> accounts {set; get{
 return [Select id,Name,Address from Account];
};}

public pageReference addAccount(){
       insert account;
       accounts.add(account);
       AccountsNo = accounts.size();

       return null;
}

in VF page

<apex:tab label="Accounts{!AccountsNo}" id="accountTab">

  // form of Required fields
  <apex:commandButton action="{!addAccount}" reRender="accountTab,accountsTable" />

  <apex:pageBlockTable id="accountsTable" ... >
  // Table code
  </apex:pageBlockTable>

</apex:tab>

Best Answer

Make this part of a form and try to rerender the whole form.

<apex:page>
 <apex:form id="pgfrm">
   <apex:tab label="Accounts{!AccountsNo}" id="accountTab">

      // form of Required fields
   <apex:commandButton action="{!addAccount}" reRender="pgfrm,accountsTable" />

    <apex:pageBlockTable id="accountsTable" ... >
       // Table code
    </apex:pageBlockTable>

    </apex:tab>
 </apex:form>
</apex:page>
Related Topic