Wednesday, 17 April 2013

Rendering HTML code on page

Below are the ways to render HTML code on JSF page:

Using <af:outputText><af:outputText value="#{pageFlowScope.testbean.value}" id="ot1" escape="false"/>

Using <af:richTextEditor><af:richTextEditor label="Label 1" id="rte1" readOnly="true" value="#{pageFlowScope.testbean.value}"/>
where bean code is using "org.apache.commons.lang.StringEscapeUtils.unescapeHtml" API to render html code properly.

import org.apache.commons.lang.StringEscapeUtils; 

public class testbean { 
 public testbean() { } 
 private String value = "&lt;
object width="100" height="100" data="http://www.google.co.in/images/srpr/logo3w.png"&gt;&lt;/object&gt;"; 
 public void setValue(String value) { 
 this.value = value; 
 } 
 public String getValue() { 
 value = StringEscapeUtils.unescapeHtml(value); return value; 
 } 
}

No comments:

Post a Comment