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
h20riderh20rider 

ApexPages.Message with a line break

I have tried adding a string with both a \n and <br>.

 

The \n does do a line return in the source

and the <br> displays <br> instead if do a br

 

How can I get it to not encode the <br>

Best Answer chosen by Admin (Salesforce Developers) 
vriavmvriavm

You can use a variable to store the error message and put a apex:outputtext with escape="false" .

In the message add <br> tag for line break this will work.

 

Controller:

String error;

if (lst.size() < 0)

   error = 'No record to display';

 

VF Page:

<apex:outputtext id="errormessage" escape="false" value="{!error}"/>

 

Note: make sure you rerender errormessage when you call submit method....

 

All Answers

vriavmvriavm

You can use a variable to store the error message and put a apex:outputtext with escape="false" .

In the message add <br> tag for line break this will work.

 

Controller:

String error;

if (lst.size() < 0)

   error = 'No record to display';

 

VF Page:

<apex:outputtext id="errormessage" escape="false" value="{!error}"/>

 

Note: make sure you rerender errormessage when you call submit method....

 

This was selected as the best answer
h20riderh20rider

thanks.  that was it.  But instead of

<apex:outputtext id="errormessage" escape="false" value="{!error}"/>

I did 

<apex:pageMessages escape="false"  />

 

thanks again

vriavmvriavm

cool man! Yup the key is escape attribute:)