You need to sign in to do that
Don't have an account?
Ravi 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;}
}
}
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;}
}
}
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">
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>
<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>
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;
}
}
}