Updating fields of sObjects
passed as attributes to custom components is straightforward, and can be achieved through simple merge syntax statements. This is not so simple when the attribute is primitive and will be updated by the component controller, as parameters are passed by value, and thus any changes are made to a copy of the primitive. For example, passing the name field of a contact sObject
, rather than the contact sObject
itself, would mean that any changes made in the component would not be visible to the containing page.
In this situation, the primitive must be encapsulated inside a containing class. The class instance attribute is still passed by value, so it cannot be updated to point to a different instance, but the properties of the instance can be updated.
In this recipe, we will create a containing class that encapsulates a Date
primitive and a Visualforce component that allows the user to enter the date via day/month/year
picklists...