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
sancasanca 

How to refer VF component's controller variable in VF page which uses that component

Hi Devs ,

I have two vf page which has similar form and fields , so thinking to design a VF component and use this vf comp in both the VF pages . 
But I want to refer the apex variable of custom controller of Vf component in VF page which uses it .
Can you please tell me how to do that ?

Regards,
Sanju
GulshanRajGulshanRaj
Hi Sanju,

Please refer this https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_comp_cust_elements_controllers.htm?search_text=component


Thanks
Gulshan Raj
sancasanca

HI Gulshan ,

I guess you didnt get my question , What i am asking is how to refer the component's controller variable in VF page which contains that VF component . To make things more clear , Let me put an example .

/* Component name :simpleComponent */

<apex:component controller="myComponentController">
<apex:attribute name="componentValue" description="Attribute on the component."
                  type="String" required="required" assignTo="{!controllerValue}"/>

componentValue is "{!componentValue}"

</apex:component>

/*Component controller*/

public class myComponentController {
    
  public String controllerValue{get;set;}
   
}

/* VF page that resides component */

<apex:page>
  <c:simpleComponent componentValue="abc"/>
how to refer    controllerValue variable here  
</apex:page>

 

Hope you got my point. 

GulshanRajGulshanRaj
Thanks @sanju for clarification.

Ideally there is no direct method through which we can interact from VF component to VF page. But there are some wayout to communicate from VF component to parent component or page.
Please follow this link https://www.sundoginteractive.com/blog/communicate-from-a-component-to-the-page-visualforce


I trust this will help you.

If this helps you, mark this question as solved and choose best answer so it will help other in future to choose best solution. 

Thanks
Gulshan Raj