Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get in a Visualforce page controller a value from a custom component controller?

I'm trying do develop a visualforce custom component which is an entity chooser. This custom component displays a UI which helps browsing 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 assignTo bug it's not bidirectional...

Hope someone can help me.. Thanks

like image 645
hrobert Avatar asked May 23 '11 21:05

hrobert


1 Answers

Are you passing an object into the component? Objects are passed by reference, so if your component has an attribute that takes an object and does something to it, your outer page controller will be able to access the changed values.

If you were to pass in a shell object, ie. if your UI is allowing a user to select an Account.

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

This would allow you to assign the user selected account into the instance of wrapper object which is owned by the outer controller. You can then reference:

instanceOfSelectedAccount.theAccount

from your main Visualforce Pages controller.

like image 74
lnediger Avatar answered Sep 28 '22 08:09

lnediger