When viewing an sObject that has a lookup relationship to another sObject, additional fields from the related sObject can be displayed on the page using formula fields. When creating a new record, or editing an existing record and changing the lookup value, formula fields cannot be used, as the lookup field has only been populated with a record ID and the related record has not been retrieved.
Name: EX03_07RetLookupFields
Populating the account lookup automatically populates the Website and Phone output elements with the details from the account:
Extension Controller
Name: EX03_07RetLookupFieldsExtVisualForce Page
Name: EX03_07RetLookupFields
Display 1
Display 2
Populating the account lookup automatically populates the Website and Phone output elements with the details from the account: