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
PleasePlease 

How to add values from a custom object in columns?

 

I get aresult but that is not usable:

I see 2 columns and 3 rows but the values are something like: 

 "core.apexpages.el.adapters.ApexObjectValueELAdapter@1083cd2"

 

 It must be because i put {!c} as value for the columns.

I want to put {!c.k} and {!c.n} in as values but then i get the error "MyCompanies.k does not exist"

 

- what do i have to do to display the elements "k" and "n" in the columns?

- is my construction for the "companies" OK?

 


This is my Controller

 

public class myController { public class myCompanies{ string k; string n; } public List<myCompanies> companies {get;set;} myCompanies mc; // fired when the search button is clicked public PageReference search() { if (companies == null) { companies = new List<myCompanies>(); // init the list if it is null } else { companies.clear(); // clear out the current results if they exist } string mykey; string myname; for (integer i = 0; i < 3; fragment++){ mykey=string.valueof(i); myname='name'+string.valueof(i); mc=null; myCompanies mc = new myCompanies(); mc.k = mykey; mc.n = myname; companies.add(mc); //system.debug('TEST: ' + companies[i].k); } return null; } }

 

and this is the VF-page

 

<apex:page controller="myController" tabStyle="Account"> <apex:form > <apex:pageBlock mode="edit" id="block"> <apex:pageBlockSection > <apex:pageBlockSectionItem > <apex:panelGroup > <apex:commandButton value="Search" action="{!search}" rerender="block" status="status"/><p /> <apex:actionStatus id="status" startText="Searching... please wait..."/> </apex:panelGroup> </apex:pageBlockSectionItem> </apex:pageBlockSection> <apex:pageBlockSection title="Search Results" id="resultsBlock" columns="1"> <apex:pageBlockTable value="{!companies}" var="c" rendered="{!NOT(ISNULL(companies))}"> <apex:column value="{!c}" headerValue="Key" /> <apex:column value="{!c}" headerValue="Name" /> </apex:pageBlockTable> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>

 

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
PleasePlease

i tackled the problem,

 

string k and string n schould be declared like: public string k {get;set;}

 

 

All Answers

Edwin VijayEdwin Vijay

I think you are correct in what you are doing..

 

Just try the following..

<apex:column headerValue="Key" > <apex:outputtext value="{!c.k}"/> </apex:column>

PleasePlease

when i try that, i still get the error: unknown property MyCompanies.k

 

 

PleasePlease

i tackled the problem,

 

string k and string n schould be declared like: public string k {get;set;}

 

 

This was selected as the best answer