2

Is there any way embed a link in an apex:Messages error message?
Below is the apex:Mesages compnent on my VF page. I cannot use apex:PageMessages because it does not support the style resources that I am using.

<apex:Messages styleclass="alert alert-error errorStyling" />

The most common solution I am seeing is to set the escape attribute to "false" under PageMessages, but this attribute is not supported in apex:Messages, only PageMessages.

Is there any way to add a link to Page:Messages like the link below?

String err = 'Testing For Message Link: <a href="http://www.google.com">Google or Something</a>.';
        ApexPages.addMessage(New ApexPages.Message(ApexPages.severity.Error, err));

          PageReference pageRef = ApexPages.currentPage();  
              return pageRef;  

Best,
CP

1 Answer 1

3

Use escape="false" and you need to use apex:pageMessages for escape

String err = 'Testing For Message Link: <a href="http://www.google.com">Google or Something</a>.';

In Page

<apex:pageMessages styleclass="alert alert-error errorStyling" escape="false"/>

Updates

If you can't use apex:pageMessages then use apex:outputText with escapse='false'

You can display this outputText when this string having value

<apex:outputText styleclass="alert alert-error errorStyling" escape="false" 
     value="{!errorString}" rendered = "{!(errorString != '')}" />

In Controller

public string str {get; private set;}

 str = 'Testing For Message Link: <a href="http://www.google.com">Google or Something</a>.';

IN VF page

<apex:outputText escape="false" value="{!str}"></apex:outputText>

NOTE:- As @Mohith Shrivastava said If you are building an appexchange product ,this wont pass security review .escape=false is not an option from security review perspective

9
  • the escape attribute is only supported in pageMessages. I cannot use pageMessages, I have to use Messages because of the style resources used.
    – Chris P
    Commented Feb 24, 2016 at 16:13
  • @ChrisP You can use apex:outputText and assign this string and use escape="false" for apex:outputText and You can add css to that apex:outputText
    – Ratan Paul
    Commented Feb 24, 2016 at 16:21
  • so it appears that the issue with that is the following: I get the messae "the value of attribute "value" in apex:outputText must not contain the '<' character. I am using te same kind of link as in my question. Maybe certain characters need to be escaped?
    – Chris P
    Commented Feb 24, 2016 at 16:42
  • @ChrisP <apex:outputText escape="false" value="{!str}"></apex:outputText> this is working for me
    – Ratan Paul
    Commented Feb 24, 2016 at 16:55
  • 2
    @Ratan Heads up !!! If you are building an appexchange product ,this wont pass security review .escape=false is not an option from security review perspective Commented Feb 24, 2016 at 18:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .