
2 réponses
ApexPages.Message is designed to work with the Visualforce managed elements for displaying such messages (apex:pageMessages and apex:messages). You wouldn't use these methods to show a popup in JavaScript, unless you were using an advanced programming technique, such as a lightbox. For a simple alert, you want pure text, not rendered HTML code that you'd have to parse/strip. This means that a @RemoteAction would be more appropriate, although this doesn't let you get to the page state.
If you want to return a simple message, the traditional means of doing so is to expose that message through a rendered element. Consider the following:
<apex:inputHidden value="{!lastMessage}" id="lastMessage" /> <apex:actionFunction action="{!myActionMethod}" reRender="lastMessage" onComplete="getLastMessage()" status="statusElement" /> <script> function getLastMessage() { var msg = document.getElementById("{!$Component.lastMessage}"); if(msg.value) alert(msg.value); } </script>