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
Raghu PedabbaRaghu Pedabba 

Multiple PageBlock Tables in Visualforce Pages

Hi,

I have created a Visualforce Page with multiple page blocks with page block table.

First Page Block Table his filled from productde and I want the second page block table to display with value from Prodcat(but its blank)

Please find my code below.

<apex:page controller="My_Controller_Class" action="{!getProd}" >
    
    <apex:form >
       <apex:pageBlock title="Product Details">
           <apex:pageBlockButtons >
              <apex:commandButton action="{!displaySelectedProd}" value="showSelected Product" 
                   rerender="Available" status="status"/>
          </apex:pageBlockButtons>
           <apex:pageBlockSection id="invoiceblock" columns="5">
            <apex:pageBlockTable value="{!productde}" var="PD">
                <apex:column >
                    <apex:inputCheckbox value="{!PD.isSelected}"/>
                    
                </apex:column>   
                <apex:column headerValue="Product Id" value="{!PD.id}"/>
                <apex:column headerValue="Product Name" value="{!PD.name}"/>
                <apex:column headerValue="Qty">
                    <apex:inputText value="{!PD.qty}" maxlength="3" size="1"/>  
                                     
                </apex:column>    
            </apex:pageBlockTable>
           </apex:pageBlockSection>
           </apex:pageBlock>
           <apex:pageBlock title="Product Availabity">
           <apex:pageblockSection id="Available" Columns="5">
               <apex:pageBlockTable value="{!prodcat}" var="PA">
                <apex:column headerValue="Product Id" value="{!PA.id}"/>
                <apex:column headerValue="Product Name" value="{!PA.name}"/>
                <apex:column headerValue="Available Qty" value="{!PA.quantity_available}"/>
            </apex:pageBlockTable>
           </apex:pageblockSection> 
       </apex:pageBlock>
    </apex:form>
</apex:page>

My Controller Class:

global class My_Controller_Class {
    
    public List<ProductDetails> ProductDe{get;set;}
    public Set<String> SelProdNames{get;set;}
    public set<integer> qty{get;set;}
    public Boolean hasSelProd{get;set;}
    public List<JSON2Apex>ProdCat{get;set;}
    
    
    public PageReference Submit(){
        return null;
    }
    
    public void getProd(){
    
       String Username =  '****';
       String password = '*****';
       String endpoint = 'http://*****/product/'; 
       String httpMethod = 'GET';
 
       Blob headerValue = Blob.valueOf(username + ':' + password);
       String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
        
        
        HttpRequest req = new HttpRequest();
        Http http = new Http();
        req.setMethod('GET');
        req.setEndpoint(endpoint);  
        req.setHeader('Authorization', authorizationHeader); 
        req.setHeader('Content-type', 'application/json');
        HTTPResponse res = http.send(req);
        System.debug(res.getBody());
        System.debug(res.toString());
        String responseStrng = res.getBody();
        
        ProductDe = (List<ProductDetails>) System.JSON.deserialize(responseStrng, List<ProductDetails>.class);
        system.debug('Product' + productde);
        ProductDe.sort();
        }

//
    public PageReference displaySelectedProd(){
        //selProdNames.clear();
        selProdNames = new Set<String>(); 
        hasSelProd = false;
       for(ProductDetails prod : ProductDe){
            if(prod.isSelected){
                hasSelProd = true;
                selProdNames.add(prod.name);
           }
        }
//
       String Username =  '*****';
       String password = '*****';
       String endpoint = 'http://**********/produc/'; 
       String httpMethod = 'GET';
 
       Blob headerValue = Blob.valueOf(username + ':' + password);
       String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
              
        HttpRequest req = new HttpRequest();
        Http http = new Http();
        req.setMethod('GET');
        req.setEndpoint(endpoint);  
        req.setHeader('Authorization', authorizationHeader); 
        req.setHeader('Content-type', 'application/json');
        HTTPResponse res = http.send(req);
        System.debug(res.getBody());
        System.debug(res.toString());
        String responseStrng = res.getBody();
        
        JSON2Apex Prodcat = JSON2Apex.parse(responseStrng);
        //ProdCat = (List<JSON2Apex>) System.JSON.deserialize(responseStrng, List<JSON2Apex>.class);
        //Prodcat = (List<JSON2Apex>) JSON.deserialize(responseStrng, List<JSON2Apex>.class);
        system.debug('ProductCat' + ProdCat);        
        
        return null;
    }
//
//      
        }



Thanks,

Raghu

Sumit Kumar Singh 9Sumit Kumar Singh 9
Hello Raghu, 
You are not calling "displaySelectedProd()" on page load, ProdCat should ne null;
There are multiple ways to do it - 

1) You can call "displaySelectedProd()" method into "getProd()".

2) Create one new method and call both the method into this method, like this - 
public void callOnPageLoad() {
     displaySelectedProd();
     getProd();
}
Then, call this mehod on Apex Page - 
<apex:page controller="My_Controller_Class" action="{!callOnPageLoad}" >

3) Create a Class constructor - and call both the methods into the constructor- if you folllow this approach, then you need not to call anyhing on page. 
public My_Controller_Class() {
    displaySelectedProd();
     getProd();
}

Pls, let me know if it helps you. 

Thnaks,
Sumti Kumar Singh
Raghu PedabbaRaghu Pedabba
Thanks Sumit.

But I am getting null pointer exception if I include DisplaySelectedProd in the Constructor.

Here is the Scenario.

When the Page loads for first time, I am trying to do a callout and get all Product Details.(First Page Block)

Then Select the Products which I want to Order, then Click a Button. (It will do a callout to return the availability status of that Product.

This Information, I need to display in my Second page Block.