Hey! Are you trying to pass an object into the component? If yes, then you know that objects are passed by reference. So, if your component has an attribute which takes an object, and some functions are applied to it, your other page controller will access the changed values.
If you want to pass in a shell object, that is, in case your UI is allowing a user to select an Account, use the following code:
Class SelectedAccount
{
public Account theAccount {get;set;}
}
Component:
<apex:component controller="ComponentController">
<apex:attribute type="SelectedAccount" name="userSelectedAccount" description="Selected Account" assignTo="{!selectedAccount}"
</apex:component>
Component Controller:
public class ComponentController
{
public selectedAccount;
public void ComponentController(){}
public PageReference selectAccountFromUI(Account selected)
{
selectedAccount.theAccount = selected;
return null;
}
}
Page using the Component:
<c:MyAccountComponent userSelectedAccount="{!instanceOfSelectedAccount}"/>
Are you willing to pursue a career in Salesforce, here's an opportunity for you Salesforce certification provided by intellipaat!