The h:outputText tag in JavaServer Faces (JSF, now Jakarta Faces) renders a value as text in the page. Unlike plain Expression Language text in a template, it can convert the value, escape HTML characters by default, apply CSS classes and styles, and be shown or hidden through its rendered attribute.
It is part of the standard HTML component library, bound to the namespace jakarta.faces.html in Faces 4 (http://xmlns.jcp.org/jsf/html in JSF 2.x).
h:outputText is a UI component (UIOutput with the javax.faces.Text or jakarta.faces.Text renderer). Given a value expression, it writes the converted value to the response. If you add no styling attributes, it writes just the text. If you add style, styleClass or id, it wraps the text in a span element.
If userBean.name is Asha, the browser receives a span with the class greeting containing Asha.
| Attribute | Purpose |
|---|---|
value | The text or value expression to display. |
escape | When true (the default) HTML special characters are escaped. |
rendered | A boolean expression deciding whether the component is output at all. |
converter | A converter used to turn the value into text. |
styleClass, style | CSS class and inline style for the generated span. |
id | Component id, useful for AJAX updates. |
title | Tooltip text. |
Because escape defaults to true, a value such as <script>alert(1)</script> is output as harmless text. This protects against cross-site scripting. Set escape="false" only when the content is trusted markup that you produced yourself, never for user input:
Plain Expression Language written directly in a Facelets template, such as #{userBean.name}, is also escaped in current versions, but it cannot take converters or attributes, and it does not create a component you can refer to in AJAX updates.
Combine h:outputText with the converters from the f tag library to format numbers and dates:
The type="localDateTime" option works with java.time types in JSF 2.3 and later. Older code uses java.util.Date with type="both".
The rendered attribute removes the component from the output without any Java code:
Give the tag an id so another component can refresh it with AJAX:
Pressing the button runs the action and replaces only the element with the id time. If the component has rendered="false", it has no element in the page, so wrap it in a container that is always rendered and update the container instead.
| Tag | Use |
|---|---|
h:outputText | Display a value as text. |
h:outputLabel | Render a label linked to an input. |
h:outputFormat | Display a message with parameters, like MessageFormat. |
h:outputLink | Render a plain a link without navigation handling. |
For internationalised messages, use a resource bundle:
No. #{bean.value} placed in the template prints the value and is escaped. Use h:outputText when you need a converter, styling, rendered or an id.
Only when you set attributes such as id, style or styleClass. Otherwise it writes the bare text.
Only for content you control. Output of user-provided data with escape="false" allows cross-site scripting.
Yes. Faces 4 uses jakarta.faces.html, while JSF 2.x uses http://xmlns.jcp.org/jsf/html, and the oldest versions use http://java.sun.com/jsf/html.
h:outputText displays a value as escaped text and supports converters, CSS, conditional rendering and AJAX updates. Prefer it when you need those features, keep escape at its default, and use plain Expression Language for simple values.