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
Ravi SriramRavi Sriram 

Wrapper class variables not showing on VF page

Hello i was trying to display info from my Wrapper Class to VF Page but i am not able to find where i was doing wrong .. could someone please help me out with this.

here are my controller and VF page codes.

VF Page
<apex:page controller="Aclist3">
  
  <apex:form >
      <apex:pageBlock >
          <apex:pageblockTable value="{!Mytablerow}" var="t">
                <apex:column value="{!t.theAccount.Name}"/>
                <apex:column value="{!t.theContact.Name}"/>
          </apex:pageblockTable>
              
      </apex:pageBlock>
              
   </apex:form>
</apex:page>

CONTROLLER



public class Aclist3 {

    public aTableRow getMytablerow() {
        return null;
    }

    Public List<aTableRow> tableRows {get; set;}
    public Aclist3()
        {
        
       List<aTableRow> tableRows = new List<aTableRow>();
       
       Account a = [SELECT Name FROM Account LIMIT 1];
       Contact c = [SELECT Name FROM Contact LIMIT 1];
       
       aTableRow Mytablerow = new aTableRow();
       
       MyTablerow.theAccount = a;
       MyTablerow.theContact = c;
             system.debug('temp******'+myTablerow.theAccount.Name);
        }

Public Class aTableRow
    {
        Public Account theAccount {get; set;}
        Public Contact theContact {get; set;}
        
        
    }
    
    
}
Gaurav PatilGaurav Patil

You are sending null value in function -->
public aTableRow getMytablerow() {
        return null;
 }

Instead directly use "tableRows" on a page. -->

 <apex:pageblockTable value="{!tableRows}" var="t">

Ravi SriramRavi Sriram
Thanks for reply, i have tried changing code as following , but still nothing is shwoing up 

CONTROLLER
Public List<aTableRow> tableRows {get; set;}
    public Aclist3()
        {
        
       List<aTableRow> tableRows = new List<aTableRow>();
       
       Account a = [SELECT Name FROM Account LIMIT 1];
       Contact c = [SELECT Name FROM Contact LIMIT 1];
       
       aTableRow Mytablerow = new aTableRow();
       
       MyTablerow.theAccount = a;
       MyTablerow.theContact = c;
       tablerows.add(MyTablerow);
             system.debug('temp******'+myTablerow.theAccount.Name);
        }

Public Class aTableRow
    {
        Public Account theAccount {get; set;}
        Public Contact theContact {get; set;}
        
        
    }
    
    
}


VF PAGE

<apex:page controller="Aclist3">
  
  <apex:form >
      <apex:pageBlock >
          tablerows.add(MyTablerow);
              
      </apex:pageBlock>
              
   </apex:form>
</apex:page>
 
Ravi SriramRavi Sriram
sorry VF PAGE   is 

<apex:page controller="Aclist3">
  
  <apex:form >
      <apex:pageBlock >
          <apex:pageblockTable value="{!tablerows}" var="t">
                <apex:column value="{!t.theAccount.Name}"/>
                <apex:column value="{!t.theContact.Name}"/>
          </apex:pageblockTable>
              
      </apex:pageBlock>
              
   </apex:form>
</apex:page>
@RohitSingh@RohitSingh
Hi Ravi,

Just try this code after few modification. Hope this will help you....

Visualforce Page 

<apex:page controller="Aclist3">
  
  <apex:form >
      <apex:pageBlock >
          <apex:pageblockTable value="{!Data}" var="t">
                <apex:column value="{!t.theAccount.Name}"/>
                <apex:column value="{!t.theContact.Name}"/>
                
          </apex:pageblockTable>
              
      </apex:pageBlock>
              
   </apex:form>
</apex:page>

Controller

public class Aclist3 {

    Public List<aTableRow> tableRows = New List<aTableRow>();
  
        Public List<aTableRow> getData(){
        
        
           List<Account> accSearch =[select id,name,Phone,(Select id,Name from Contacts)from Account Where Name = 'XXXX' limit 1];

 for(Account accRec:accSearch)
 {
     for(Contact gpa:accRec.contacts)
     {
             tableRows.add(new aTableRow(accRec, accRec.contacts));   
     }
 }
            
        return tableRows;
        }           
Public Class aTableRow
    {
        Public Account theAccount {get; set;}
        Public Contact theContact {get; set;}

        Public aTableRow(Account acc , Contact con){
        
        this.theAccount = acc;
        this.theContact = con;
        }
        
    }
}
Ravi SriramRavi Sriram
hi @RohitSingh, i have tried copying excat same code but still the page is blank. (