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
FastSnailFastSnail 

Component controller based on component attribute?

Hello,
I have a component that is used by multiple pages, displaying different data (in the same layout) based on the page it is loaded in.
Both the Page and the Component use the same controller, the logic of the component controler is embedded in the page controller logic.
Is there a way for the page to pass its controller name as an attribute to the compoent? It works fine for language but it seems that controller value must be only string between " ".  Any workaround?
Thanks in advance for your help and any idea. Otherwise, I have to create one component to fit each page, just different in their controller name. What I would like is something like:
<apex:page controller=" ControlerForThisPage" >
<c:componentName controller= "ControlerForThisPage" language= "en_US" />     <!--assigning controller value on component -->
<…
</apex :page>
Component :
<apex:component controller= "{ !controller}" language="{ !language}" >  <!--  How to pass ControlerForThisPage here? -->
<apex:attribute name=controller type="string" ..
<apex:attribute name=language  type="strng" ..
<..
</apex:component>
 
Best Answer chosen by FastSnail
Grazitti TeamGrazitti Team
Hi Snail,

The salesforce does not provide the facility to pass the controller as attribute from the page to component.
Here the link that explains which attributes we can pass from page to component:
http://www.salesforce.com/docs/developer/pages/Content/pages_compref_attribute.htm

I would like to give one suggest that you should put your component controler logic in the separate Apex class and associated that class with the component. This will help you to solve the problem.

Please Mark this as Best Answer if it helps you

Regards,
Grazitti Team
Web: www.grazitti.com
Email: sfdc@grazitti.com

All Answers

Grazitti TeamGrazitti Team
Hi Snail,

The salesforce does not provide the facility to pass the controller as attribute from the page to component.
Here the link that explains which attributes we can pass from page to component:
http://www.salesforce.com/docs/developer/pages/Content/pages_compref_attribute.htm

I would like to give one suggest that you should put your component controler logic in the separate Apex class and associated that class with the component. This will help you to solve the problem.

Please Mark this as Best Answer if it helps you

Regards,
Grazitti Team
Web: www.grazitti.com
Email: sfdc@grazitti.com
This was selected as the best answer
FastSnailFastSnail
Hello Grazitti Team,
Thank you for such a quick reply.  It is what I thought.  I cannot put my component controller in an independant Controller from the page because the page passes attribute value to the component controller that needs to be set when the component initializes, which is not possible (assignTo are set AFTER the component loads). Anyway, thanks for the suggestion.
All the best,
Jerome