function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
GlennAtAppirioGlennAtAppirio 

Adding Apex Messages During Initial Page Load

We're using the <apex: pageMessages> tag to set and display error messages to users.

However, the tag doesn't seem to display if messages are set (via ApexPages.addMessage()) during the initial page load, i.e. within the controller's constructor. The page messages display fine upon any reload (e.g. after calling an action from a button).

This is unfortunate. We do lots of lookups in the constructor based on URL parameters, and want to display error messages in certain situations.

We've hacked around this for now by re-creating the <apex: pageMessages> look & feel within an apex: outputPanel, and then writing some controller code to parse the existing message list and set a member variable accordingly. But this is definitely a hack.

Are we missing something? We'd love to be able to set and display <apex: pageMessages> during the initial page load.

Message Edited by GlennAtAppirio on 09-22-2008 09:16 AM
jwetzlerjwetzler
can you use the action attribute on the page component to add your message and then return null (should cause a refresh of the page)?
GlennAtAppirioGlennAtAppirio
Jill - perfect!!! Thank you. We kept just the basics (e.g. variable initialization) in the constructor, and moved any logic that might result in an error to an initialize() function, which we then set as the "action" from our top-level page tag. It worked beautifully.

Thanks for the quick response!