// Code:
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'This is an info message with a <a href="http://www.google.com/">link to google</a>.'));
<!-- Page: -->
<apex:pagemessages escape="false">
I soon noticed that sometimes the link appeared correctly, and other times the HTML was escaped and so you'd just see the markup in the message rather than a link — it took me a short while to notice a difference between the two scenarios, they were both using the same action and the same line of code to add the message to the page so it didn't appear to make any sense. After some head scratching I finally noticed that in the case where the link did work, I had one message with Severity.ERROR and then one which has Severity.INFO and the link, as per the code snippet above; in the case where the link wasn't working I had two Severity.INFO messages.
My conclusion? There's a bug within VisualForce whereby the use of two messages of the same type will cause the escape attribute to be overridden, meaning the HTML is always escaped. I could be wrong, but I wrote a quick page to test this idea and it appears to confirm my thinking, the screenshots below demonstrate the issue perfectly:
At this point I don't have a solution to the issue, but hopefully if you're encountering this problem it'll help provide some insight into what's going on.
*On a side note, if you use <apex:messages/> you'll find your messages are displayed without formatting, if you use <apex:pageMessages/> then they use the default Salesforce styling and look much nicer.



0 comments:
Post a Comment