+ Start a Discussion

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 ?

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

Gulshan Raj

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}"


/*Component controller*/

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

/* VF page that resides component */

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


Hope you got my point. 

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. 

Gulshan Raj