I have several visualforce components inside a Visualforce page. Instead of doing my SOQL queries inside each component (through an apex controller), I'd like to have a single soql query inside the VF page controller and pass resulting data (ieally as an array) to my VF components.

Current Page Code looks like: <c:component1 /> <c:component2 />

Is passing values (as an array) into these components through the vf page housing them possible to do?


Yes it is. You can pass in specific values:

    <apex:attribute name="sobs" type="MyCustomObject__c[]" description=""/>

or indeed a reference to the page controller

    <apex:attribute name="c" type="PageController" description=""/>

and then use expressions like { !c.property } to reference values from the controller.

Just a question of whether you want the component to be fully self-contained or not.

| improve this answer | |
  • Thanks Keith! This is great to know. – ust Nov 22 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.