In JSF 2.0 web application, “h:outputText” tag is the most common used tag to display plain text, and it doesn’t generate any extra HTML elements. See example…

1. Managed Bean

A managed bean, provide some text for demonstration.

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 = "<input type='text' size='20' />"; //getter and setter methods...
}

2. View Page

Page with few “h:outputText” tags example.

JSF…

<?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>

Generate following HTML code…

<!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">
<body>
<h1>JSF 2.0 h:outputText Example</h1>
<ol>
<li>This is Text!</li> <li>This is Text!</li> <li><span class="abc">This is Text!</span></li> <li><input type='text' size='20' /></li> <li><input type='text' size='20' /></li>
</ol>
</body>
</html>

For case 1 and 2

In JSF 2.0, you don’t really need to use “h:outputText” tag, since you can achieve the same thing with direct value expression “#{user.text}”.

For case 3

If any of “styleClass”, “style”, “dir” or “lang” attributes are present, render the text and wrap it with “span” element.

For case 4 and 5

The “escape” attribute in “h:outputText” tag, is used to convert sensitive HTML and XML markup to the corresponds valid HTML character.

For example,

        < convert to &lt;
> convert to &gt;
& convert to &amp;

By default, “escape” attribute is set to true.

3. Demo

URL : http://localhost:8080/JavaServerFaces/

JSF 2 outputText example的更多相关文章

  1. JSF request参数传递

    转载自:http://blog.csdn.net/duankaige/article/details/6711044 1:JSF页面之间传参 方法1: <h:outputLink value=& ...

  2. 关于JSF中immediate属性的总结(二)

    The immediate attribute in JSF is commonly misunderstood. If you don't believe me, check out Stack O ...

  3. JSF标签的使用2

    n  事件监听器是用于解决只影响用户界面的事件 Ø  特别地,在beans的form数据被加载和触发验证前被调用 •    用immediate=“true”指明这个行为不触发验证 Ø  在监听器调用 ...

  4. JSF 与 HTML 标签的联系

    *页面的开头 <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%> <%@ t ...

  5. JSF的ui标签

    在使用自己的tag时,首先需要在web.xml里面进行注册,注册方式是在web.xml开头加上:  <context-param>        <param-name>fac ...

  6. JSF 2 link, commandLink and outputLink example

    In JSF, <h:link />, <h:commandLink /> and <h:outputLink /> tags are used to render ...

  7. JSF HelloWord

    JSF(Java Server Faces)是一种用于构建Web应用程序的新标准Java框架.提供了一种以组件为中心来开发Java Web的用户界面的方法,从而简化了开发.   JSF是Java We ...

  8. JSF开篇之Login案例

    开发环境:Myeclipse+JDK5+MyEclipse Tomcat+jsf2.2.8 JSF看起来和STRUTS还是有些像的,刚开始还是遇到一点问题:资源包的存放路径及文件访问路径. 开发Log ...

  9. JSF 2 textarea example

    In JSF, you can use the <h:inputTextarea /> tag to render a HTML textarea field. For example, ...

随机推荐

  1. disable-linux-firewall-under-centos-rhel-fedora

    http://www.cyberciti.biz/faq/disable-linux-firewall-under-centos-rhel-fedora/

  2. topcoder srm 610 div2 250

    第一次做tc 的比赛,一点也不懂,虽然题目做出来了, 但是,也没有在比赛的时候提交成功.. 还有,感谢一宁对tc使用的讲解.. 贴一下代码..... #include <cstring> ...

  3. POJ 2455 - Secret Milking Machine

    原题地址:http://poj.org/problem?id=2455 题目大意:给出一个N个点的无向图,中间有P条边,要求找出从1到n的T条通路,满足它们之间没有公共边,并使得这些通路中经过的最长的 ...

  4. 关于ie6对齐

    先来没有任何对齐时的样子: 1.一种是在父级没有高度的情况下居中. 给每个独立的元素都加上vertical-align:middle; 针对文字可以不加,加与不加都可以居中对齐.但是无法做到绝对的居中 ...

  5. codevs 1135 选择客栈

    这题没什么话说. #include<iostream> #include<cstdio> #include<cstring> #include<algorit ...

  6. BZOJ 3527 力

    fft推下公式.注意两点: (1)数组从0开始以避免出错. (2)i*i爆long long #include<iostream> #include<cstdio> #incl ...

  7. Swift compile slow 编译慢问题

    http://stackoverflow.com/questions/29707622/bizarre-swift-compiler-error-expression-too-complex-on-a ...

  8. css3属性及事例

    在看网上别的前端大牛的作品时,总会有新的收获,我想很多人应该都知道box-shadow,但是不知道有没有接触过这个 box-shadow: 2px 2px 4px rgba(0,0,0,0.4)  , ...

  9. Hibernate管理Session和批量操作

    Hibernate管理Session Hibernate自身提供了三种管理Session对象的方法 Session对象的生命周期与本地线程绑定 Session对象的生命周期与JTA事务绑定 Hiber ...

  10. gtid

    GTID的全称为 global transaction identifier,可以翻译为全局事务标示符,GTID在原始master上的事务提交时被创建.GTID需要在全局的主-备拓扑结构中保持唯一性, ...