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
SFDC DummySFDC Dummy 

How to Use two Page BlockTable in single Page Block

Hi

I have created a Vf page .but i am unable to use two page block table in single page block.how its possible can any body tell me
 
<apex:page tabstyle="Account" showHeader="false" sidebar="false" Controller="ManageListController1">

<apex:define name="body">
            
            <div style="width:900px;margin: 10px auto 10px auto;background-color:Gray;">
            
 <apex:form >
 

   <apex:pageBlock title="Bank Book Entry:">
      <apex:pageBlockSection columns="2"> 
      
      <apex:pageBlockTable value="{!wrappers1}" var="wrapper1" id="wtable1">
      <apex:column headerValue="Date" style="background:gray;">
           <apex:outputText value="{!wrapper1.Txn_Date__c}"/>
         </apex:column>
      
      
      </apex:pageBlockTable>
      
          
   <div style="width:500px;margin: 10px auto 10px auto;">
   
      <apex:pageBlockTable value="{!wrappers}" var="wrapper" id="wtable">
       
         <apex:column headerValue="Ident" style="background:gray;">
            <apex:outputText value="{!wrapper.ident}"/>
         </apex:column>
         <apex:column headerValue="Master Code" style="background:gray;">
            <apex:inputField value="{!wrapper.acc.Entries_Code__c}"/>
         </apex:column>
         <apex:column headerValue="Amount" style="background:gray;">
            <apex:inputField value="{!wrapper.acc.Amount__c}"/>
         </apex:column>
         <apex:column headerValue="Narration" style="background:gray;">
            <apex:inputField value="{!wrapper.acc.Narration__c}"/>
         </apex:column>
          
       <apex:column headerValue="">
            <apex:commandButton value="Enter" action="{!addRows}" rerender="wtable" style="background:pink" >
         <apex:param name="addCount" value="1" assignTo="{!addCount}"/> 
      </apex:commandButton>
         </apex:column>
       
         <apex:column headerValue="Action">
            <apex:commandButton value="Delete" action="{!delWrapper}" rerender="wtable" style="background:Red">
               <apex:param name="toDelIdent" value="{!wrapper.ident}" assignTo="{!toDelIdent}"/> 
            </apex:commandButton>
         </apex:column>
         
      </apex:pageBlockTable>
     </div>
        
        
      <apex:commandButton value="Add 5 Rows" action="{!addRows}" rerender="wtable" style="width:100px;margin: 10px auto 10px auto;">
         <apex:param name="addCount" value="5" assignTo="{!addCount}"/> 
      </apex:commandButton>
      
      <apex:commandButton value="Save" action="{!save}" style="width:100px;margin: 10px auto 10px auto;"/>
   
     </apex:pageBlockSection>
     </apex:pageBlock>
 </apex:form>
  </div>
        </apex:define>
</apex:page>
 
public class ManageListController1 
{

    
    public ManageListController1(ApexPages.StandardController controller) {

    }

 public List<AccountWrapper> wrappers {get; set;}
  public List<AccountWrapper> wrappers1 {get; set;}
 public static Integer toDelIdent {get; set;}
 public static Integer addCount {get; set;}
 private Integer nextIdent=0;
  
 public ManageListController1()
 {
  wrappers=new List<AccountWrapper>();
  Wrappers1=new List<AccountWrapper>();
  for (Integer idx=0; idx<1; idx++)
  {
   wrappers.add(new AccountWrapper(nextIdent++));
    wrappers1.add(new AccountWrapper(nextIdent++));
   
  }
 }
  
 public void delWrapper()
 {
  Integer toDelPos=-1;
  for (Integer idx=0; idx<wrappers.size(); idx++)
  {
   if (wrappers[idx].ident==toDelIdent)
   {
    toDelPos=idx;
   }
  }
   
  if (-1!=toDelPos)
  {
   wrappers.remove(toDelPos);
  }
 }
  
 public void addRows()
 {
  for (Integer idx=0; idx<addCount; idx++)
  {
   wrappers.add(new AccountWrapper(nextIdent++));
  }
 }
  
 public PageReference save()
 {
  List<BankBook__c> accs=new List<BankBook__c>();
  for (AccountWrapper wrap : wrappers)
  {
   accs.add(wrap.acc);
  }
   
  insert accs;
   
  return new PageReference('/' + Schema.getGlobalDescribe().get('BankBook__c').getDescribe().getKeyPrefix() + '/o');
 }
 
 public pageReference parentPage () {

          return new pageReference('/apex/Receivables');
} 
  
  
  
 public class AccountWrapper
 {
  public BankBook__c acc {get; private set;}
  public Integer ident {get; private set;}
   
  public AccountWrapper(Integer inIdent)
  {
   ident=inIdent;
   acc=new BankBook__c();
  }
 }
}

 
Jigar.LakhaniJigar.Lakhani
Hello,

We can use multiple pageblocktables in single pageblock without any limitation. Can you please share compilation error ?

Thanks & Cheers,
Jigar(pateljb90@gmail.com)
Jigar.LakhaniJigar.Lakhani
Hi,

Please replace your visualforce page code with below code.
 
<apex:page tabstyle="Account" showHeader="false" sidebar="false" Controller="ManageListController1">

<apex:define name="body">       
<div style="width:900px;margin: 10px auto 10px auto;background-color:Gray;">
<apex:form >

	<apex:pageBlock title="Bank Book Entry:">
   
		<apex:pageBlockSection> 
		
			<apex:pageBlockTable value="{!wrappers1}" var="wrapper1" id="wtable1">
				<apex:column headerValue="Date" style="background:gray;">
				<apex:outputText value="{!wrapper1.Txn_Date__c}"/>
				</apex:column>
			</apex:pageBlockTable>
		
		</apex:pageBlockSection>
		
		<apex:pageBlockSection>
			
			<div style="width:500px;margin: 10px auto 10px auto;">
			<apex:pageBlockTable value="{!wrappers}" var="wrapper" id="wtable">
				<apex:column headerValue="Ident" style="background:gray;">
					<apex:outputText value="{!wrapper.ident}"/>
				</apex:column>
				<apex:column headerValue="Master Code" style="background:gray;">
					<apex:inputField value="{!wrapper.acc.Entries_Code__c}"/>
				</apex:column>
				<apex:column headerValue="Amount" style="background:gray;">
					<apex:inputField value="{!wrapper.acc.Amount__c}"/>
				</apex:column>
				<apex:column headerValue="Narration" style="background:gray;">
					<apex:inputField value="{!wrapper.acc.Narration__c}"/>
				</apex:column>
			  
				<apex:column headerValue="">
					<apex:commandButton value="Enter" action="{!addRows}" rerender="wtable" style="background:pink" >
					<apex:param name="addCount" value="1" assignTo="{!addCount}"/> 
					</apex:commandButton>
				</apex:column>
				<apex:column headerValue="Action">
					<apex:commandButton value="Delete" action="{!delWrapper}" rerender="wtable" style="background:Red">
						<apex:param name="toDelIdent" value="{!wrapper.ident}" assignTo="{!toDelIdent}"/> 
					</apex:commandButton>
				</apex:column>
			</apex:pageBlockTable>
			</div>
			
		</apex:pageBlockSection>
		
		<apex:pageBlockSection>
		
			<apex:commandButton value="Add 5 Rows" action="{!addRows}" rerender="wtable" style="width:100px;margin: 10px auto 10px auto;">
				<apex:param name="addCount" value="5" assignTo="{!addCount}"/> 
			</apex:commandButton>
		  
			<apex:commandButton value="Save" action="{!save}" style="width:100px;margin: 10px auto 10px auto;"/>
		
		</apex:pageBlockSection>
		
	</apex:pageBlock>
	 
</apex:form>
</div>
</apex:define>

</apex:page>

Thanks & Cheers,
Jigar(pateljb90@gmail.com)
SFDC DummySFDC Dummy
[image: Error]Error: Unknown property 'ManageListController1.AccountWrapper.Txn_Date__c' This is the compilation error.i nned to create two section with the help of page blocktable in section one i will selected date value and in section two i will select payment details [image: Inline image 1]
Jigar.LakhaniJigar.Lakhani
Hi,

Your compilation error is because of property not available in you wrapper class. I think you are trying to user Txn_Date__c field of BankBook__c object.

Replace below code
<apex:column headerValue="Date" style="background:gray;">
	<apex:outputText value="{!wrapper1.Txn_Date__c}"/>
</apex:column>

With
<apex:column headerValue="Date" style="background:gray;">
	<apex:outputText value="{!wrapper1.acc.Txn_Date__c}"/>
</apex:column>

It will resolve compilation error.

Thanks & Cheers,
Jigar(pateljb90@gmail.com)
SFDC DummySFDC Dummy
Its saved but not fetching the date field in Vf layout