In the previous recipe, Adding error messages to field inputs, the platform took care of positioning the error message based on whether the field had any errors associated with it. Visualforce automatically provides this functionality for <apex:inputField />
components, but if a different input component is used, such as <apex:inputText />
or <apex:selectList />
, there is no equivalent functionality.
In this recipe, we will create a Visualforce page to allow a user to create or edit a contact record. The contact standard controller and a controller extension manage the page. The ID of the account that the contact is associated with is entered via an <apex:selectList />
component, which is bound to a controller property rather than an sObject
field. If the user does not select an account to associate the contact with, an error message is displayed under the <apex:selectList />
component.