PDI · Question #118
A custom Visualforce controller calls the ApexPages,addMessage () method, but no messages are rendering on the page. Which component should be added to the Visualforce page to display the message?
The correct answer is A. <apex: pageMessages />. To display messages added to ApexPages.addMessage() from an Apex controller on a Visualforce page, the <apex:pageMessages /> component is required.
Question
A custom Visualforce controller calls the ApexPages,addMessage () method, but no messages are rendering on the page. Which component should be added to the Visualforce page to display the message?
Options
- A<apex: pageMessages />
- B<apex: pageMessage severity="info''/>
- C<Apex: facet name='' message''/>
- D<Apex: message for='' info''/>
How the community answered
(42 responses)- A88% (37)
- B7% (3)
- C2% (1)
- D2% (1)
Why each option
To display messages added to `ApexPages.addMessage()` from an Apex controller on a Visualforce page, the `<apex:pageMessages />` component is required.
The `<apex:pageMessages />` component displays all messages, including errors, warnings, and information messages, that have been added to `ApexPages` in the controller.
The `<apex:pageMessage>` component is used to display a single, static message defined directly on the Visualforce page, not dynamic messages from `ApexPages.addMessage()`.
The `<apex:facet>` component defines a specific area within a parent component and is not used for displaying `ApexPages` messages.
The `<apex:message>` component displays an error message associated with a specific input field, not general or global messages from `ApexPages.addMessage()`.
Concept tested: Visualforce page message display
Source: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_pageMessages.htm
Topics
Community Discussion
No community discussion yet for this question.