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
AloneAlone 

Show an URL in VF page from Controller

HI,

 

I have catch block and  I am showing the custom error message to User using

ApexPages.addMessage(myMsg); 

 

But is there any way to show and URL along with the message, I was able to create URL dynamically but when I added along with the message it show as simple text, I need to show as link to location.

 

 

My Code:

------------------------

 }catch(QueryException e){
                       
   String URL='http://';
                       

                        URL += ApexPages.currentPage().getHeaders().get('Host');
                        URL += '/'+ApexPages.currentPage().getParameters().get('id');
                                              
                       
                        ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'

                        You do not have access to this Opportunity. '+URL);
                        ApexPages.addMessage(myMsg);                   
                       
               } 

 

 

Anoop

bob_buzzardbob_buzzard

I don't think you can add additional styling in the pagemessages component, as this already styles the content appropriately for warning/info/error etc.  You may be able to do something with javascript once the page is loaded, or you could look at producing your own error block, neither of which are ideal.

vanessenvanessen

You can set a boolean showError{get;set;} and a message as String message{get;set;}

 

 }catch(QueryException e){
                       
   String URL='http://';
                       

                        URL += ApexPages.currentPage().getHeaders().get('Host');
                        URL += '/'+ApexPages.currentPage().getParameters().get('id');
                                              
                       
                        String message = 'You do not have access to this Opportunity. '+ ' <a href=\'' + URL +' \' >' +URL + '</a>';

                        showError = true;                                       
                       
              

and then on your page place an outputText or outputPanel that render when the boolean showError is true and then use an outputText with escape= false to render html with the mesage as value and apply an style for the text to appear red.

Cory CowgillCory Cowgill

I think Vanessen's solution will work, so if you need to do HTML Error messages immediately that is one option.

 

My only word of caution would be that if you set escape=false on a VF page it will show as a XSS vulnerabiliity in any Force.com Security Scanner reviews (http://security.force.com/sourcescanner).

 

In Winter 12 you may want to look at Dynamic Visulaofrce Components, which allows you to generate Visualforce Markup from the Controller. This feature is in Pilot only though for Winter 12, so Spring 12 will probably be earliest it would be GA.