0 votes
1 view
in Salesforce by (11.9k points)

I'm trying to develop a visualforce custom component which is an entity chooser. This custom component displays a UI which helps to browse some records. It's possible to select one record, and I'd like to get it from outside the component or its controller.

I've looked at the standard salesforce binding with an assignTo bug it's not bidirectional...

Hope someone can help me. Thanks

1 Answer

0 votes
by (29.8k points)

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

...