Say I have a VisualForce page with a VisualForce Component on the page and I pass a variable to the component.

Does the component have the reference to that variable?

If I were to manipulate the variable in the component controller, would the VisualForce page controller have the same value?

  • 1
    It's by reference. As long as the type is mutable you would be able to modify it in place. – Adrian Larson Jul 10 '17 at 18:31
  • 1
    Are you trying to get at what values can be modified directly when passing to a component? As you see the whole pass by reference/value becomes a semantics thing and confuses the issue – Eric Jul 10 '17 at 18:55

It depends on what you're assigning, and how it's being accessed.

apex:attribute name="propName"

This is a two-way binding as long as you are only in Visualforce. You can't access the attribute in Apex Code, but you can bind it to input or output elements, which can be user-modified.

apex:attribute name="propName" assignTo="{!someMemberVar}"

This is a one-way binding in Apex Code at the variable level, because only the setter will be called. However, if someMemberVar is a non-primitive, you can assign new values to its members, and it'll be passed back to the page, because it is assigned by reference. I've explained a lot more in some answers like this one.


If the attribute is assigned an expression, the value won't propagate back to the page. In other words, if you assign a value of {!memberVar+5}, then memberVar won't be updated (it's effectively read-only).

| improve this answer | |
  • This seems to me a visualforce component related question. aura attributes cannot be the answer – Christian Szandor Knapp Jul 10 '17 at 21:24
  • 1
    @ChristianSzandorKnapp Those are typos. Too much Lightning on the brain. One sec. – sfdcfox Jul 10 '17 at 21:28

It depends on what kind of data type you are passing. All primitive types are pass by value whereas non-primitive is passed by reference. This is a good blog and this

| improve this answer | |
  • Hmm, this seems to be for apex. @AdrianLarson believes components to be pass by reference – TemporaryFix Jul 10 '17 at 18:46
  • Yes, I agree even though making it look like "pass by value", but its always reference. It creates a new reference every primitive type integer, string, double are immutable once constructed with a value, they can never be changed. Any operation just creates a new Object using the value as a base, so it seems they are passed by value, but its memory reference always. – Avijit Chakraborty Jul 10 '17 at 18:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.