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
ministe_2003ministe_2003 

Table and list on custom component without controller?

Hi all,

I'm trying to make a custom component out of a visualforce page I have because I've found another use for it, but with a different object.  Rather than re-write it all I figured I'd stick it into a component.  In this component I want to pass it a list of query results and display them in a table.  These results will be of different sobject types in my two different use cases, so I can't hard code the attribute type, so I'm passing sobject[] as the type, which seems to work.

 

Problem is I want to display data in the table columns and if I use this, I get an error:

 

<apex:attribute name="searchResults" type="SObject[]" required="true" description="which will store search results as a list of a type of SObjects"/>

<apex:dataTable id="resultsTable" value="{!searchResults}" var="sr">
 <apex:column headerValue="Search Results" width="100%">
  <apex:outputLabel id="nameLabel" value="{!sr.Name}" onclick="selectRecord('{!sr.Id}');"/>
 </apex:column>
</apex:dataTable>

 The error I get is:

Error: Unknown property 'SObject.Name'

 

Which relates to sr.Name.

 

I don't want to have to create a controller for this component if I can avoid it becuase I want to control its functionality from the controllers I will write for each of the two use cases I have right now, so is there a way I can display the data from a list I pass as a component?  The data does appear to be in there because if I just have value="test" in the output label, I get mulriple rows of the word "test", one for each of the results in the table, so the data must be in there somewhere - how do I get my component to display it?

 

Thanks

Shiv ShankarShiv Shankar

Hi ministe,

 

Since you are using property in your custom component, so you have to use controller for it.