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
pramod1.3932219482734224E12pramod1.3932219482734224E12 

How to pass value from component controller to page controller?

Component: <apex:component controller="componentController">
<apex:attribute name="value" required="true" type="object" description="need to pass selectedValue to page."/>
</apex:component>  

Component Controller:
public class componentController{  
public String selectedValue {get; set;}
}    

Page:
<apex:page controller="pageController">
<apex:form > <apex:outputText value="{!selectedValue}/>  
</apex:page>  

Page Controller:
public class pageController {
public String selectedValue {get; set;}  
}
Agustina GarciaAgustina Garcia
You would need to use a single controller for the component and the page, and call in the page to the componet. Look at this example, and the result if we open the page in the browser.

User-added image
 
public class MyComponentController
{  
    public String vfValue;
    public String selectedValue;
	
    public MyComponentController()
    {
        vfValue='Value1';
    }
    
    public void setSelectedValue (String s)
  	{
		selectedValue = s;
	}

	public String getSelectedValue()
    {
    	return selectedValue;
    }
    
    public String getVfValue()
    {
        return vfValue;
    }
    
    public void setVfValue(String v)
    {
        vfValue = v;
    }
}
<apex:component controller="MyComponentController">
    <apex:attribute name="mySelectedValue" required="required" type="String" description="need to pass selectedValue to page." assignTo="{!selectedValue}"/>
    <apex:outputText value="{!selectedValue}"/>                     
</apex:component>
<apex:page controller="MyComponentController">
	<apex:form >
        <apex:sectionHeader Title="VF page with component">
			<c:mycomponent mySelectedValue="{!vfValue}"/>
        </apex:sectionHeader>
	</apex:form>
</apex:page>