apex:messages

All messages that were generated for all components on the current page. If an <apex:message> or <apex:messages> component is not included in a page, most warning and error messages are only shown in the debug log.

This component supports HTML pass-through attributes using the “html-” prefix. Pass-through attributes are attached to the generated <ul> tag. (Each message is contained in a list item.)

Example 

1<!-- For this example to render properly, you must associate the Visualforce page 
2with a valid account record in the URL. 
3For example, if 001D000000IRt53 is the account ID, the resulting URL should be: 
4https://MyDomain_login_URL/apex/myPage?id=001D000000IRt53
5See the Visualforce Developer's Guide Quick Start Tutorial for more information. -->
6         
7
8<!-- Page:  -->
9<apex:page controller="MyController" tabStyle="Account">
10    <apex:messages />
11    <apex:form > 
12        <apex:pageBlock title="Hello {!$User.FirstName}!">
13        This is your new page for the {!name} controller. <br/>
14        You are viewing the {!account.name} account.
15
16        <p>Number of Locations: <apex:inputField value="{!account.NumberofLocations__c}" 
17            id="Location_validation"/> 
18        (Enter an alphabetic character here, then click save to see what happens.) </p>
19           
20        <p>Number of Employees: <apex:inputField value="{!account.NumberOfEmployees}" 
21            id="Employee_validation"/> 
22        (Enter an alphabetic character here, then click save to see what happens.) </p>
23            <p /> 
24        <apex:commandButton action="{!save}" value="Save"/>    
25         <p />
26        </apex:pageBlock>  
27    </apex:form>  
28</apex:page>
29
30/*** Controller  ***/
31public class MyController {
32    Account account;
33
34    public PageReference save() {
35    try{
36        update account;
37    }
38    catch(DmlException ex){
39        ApexPages.addMessages(ex);
40    }
41    return null;
42    }
43
44    public String getName() { 
45        return 'MyController';
46    }
47
48    public Account getAccount() {
49        if(account == null)
50        account = [select id, name, numberofemployees, numberoflocations__c from Account
51        where id = :ApexPages.currentPage().getParameters().get('id')];
52        return account;
53
54    }
55}

Attributes 

Attribute NameAttribute TypeDescriptionRequired?API VersionAccess
dirStringThe direction in which the generated HTML component should be read. Possible values include “RTL” (right to left) or “LTR” (left to right). 10.0global
globalOnlyBooleanA Boolean value that specifies whether only messages that are not associated with any client ID are displayed. If not specified, this value defaults to false. 10.0global
idStringAn identifier that allows the message component to be referenced by other components in the page. 10.0global
langStringThe base language for the generated HTML output, for example, “en” or “en-US”. For more information on this attribute, see the W3C specifications. 10.0global
layoutStringThe type of layout used to display the error messages. Possible values for this attribute include “list” or “table”. If not specified, this value defaults to “list”. 10.0global
renderedBooleanA Boolean value that specifies whether the component is rendered on the page. If not specified, this value defaults to true. 10.0global
styleStringThe style used to display the messages, used primarily for adding inline CSS styles. 10.0global
styleClassStringThe style class used to display the messages, used primarily to designate which CSS styles are applied when using an external CSS stylesheet. 10.0global
titleStringThe text to display as a tooltip when the user’s mouse pointer hovers over this component. 10.0global

See Also