JSF Tutorial - JSF OutputText Example

The h:outputText tag renders an HTML text.

The following JSF code

<h:outputText value="Hello World!" />

is rendered into the following HTML code.

Hello World!

Tag Attributes

idid for the tag
bindingReference to the component used in a backing bean
renderedA boolean value; false would suppress rendering
styleClassCascading stylesheet (CSS) class name
valuevalue binding
converterConverter class name
styleInline style information
titleA title used for accessibility. Browsers typically create tooltips for the title's value


The following code is from demo.xhtml.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
<html xmlns="http://www.w3.org/1999/xhtml"   

      <h1>JSF 2.0 h:outputText Example</h1>
     <li><h:outputText value="#{user.text}" /></li>
    <li><h:outputText value="#{user.text}" styleClass="abc" /></li>
    <li><h:outputText value="#{user.htmlInput}" /></li>
    <li><h:outputText value="#{user.htmlInput}" escape="false" /></li>

The following code is from UserBean.java.

package com.java2s.common;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

public class UserBean{

  public String text = "This is Text!";
  public String htmlInput = "<a href='http://java2s.com'>java2s.com</a>";
  public String getText() {
    return text;
  public void setText(String text) {
    this.text = text;
  public String getHtmlInput() {
    return htmlInput;
  public void setHtmlInput(String htmlInput) {
    this.htmlInput = htmlInput;

Download OutputText.zip


Copy the generated WAR file from the target folder to Tomcat deployment folder and run Tomcat-Install-folder/bin/startup.bat.

After Tomcat finish starting, type the following URL in the browser address bar.