Writing html to a string

I am trying to write a couple of small html lines in my java class that gets some data from another API. I get the data in a JSON string and would like to display some of it on a web page.

To create HTML, I try:

StringBuilder sb = new StringBuilder(); for(int i=0;i<leads.size();i++){ sb.append("<p>Name: "+leads.get(i).getFirstName()+" "+leads.get(i).getLastName()+"</p>"); sb.append("<p>Email: "+leads.get(i).getEmail()+"</p>"); sb.append("<br />"); } fullLeadData = sb.toString(); 

But what is ultimately displayed is a literal interpretation of the html tags. Is there a way I can create this string so that the tags remain as tags and not escaped characters?

The java class is a managed bean, so in html I have:

  <body> <div id="display"> #{PortalView.fullLeadData} </div> </body> 

Where fullLeadData is a line with html.

+7
source share
2 answers

It looks like you are using JSF. Try the following:

 <div id="display"> <h:outputText value="#{PortalView.fullLeadData}" escape="false"/> </div> 
+7
source

You may need to replace the escape sequences. Are common

 '&' (ampersand) '&amp;' '"' (double quote) '&quot;' "' (single quote) '&#039;' '<' (less than) '&lt;' '>' (greater than) '&gt;' 
+1
source

All Articles