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!
Attribute | Description |
---|---|
id | id for the tag |
binding | Reference to the component used in a backing bean |
rendered | A boolean value; false would suppress rendering |
styleClass | Cascading stylesheet (CSS) class name |
value | value binding |
converter | Converter class name |
style | Inline style information |
title | A 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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"> <h:body> <h1>JSF 2.0 h:outputText Example</h1> <ol> <li>#{user.text}</li> <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> </ol> </h:body> </html>
The following code is from UserBean.java.
package com.java2s.common; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; @ManagedBean(name="user") @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; } }
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.
http://localhost:8080/simple-webapp/demo.xhtml