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. HDU 4633 Who's Aunt Zhang(polay计数)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4633 题意:有下面一个魔方.有K种颜色.可以为顶点.边.面(每个面有9个小面)染色.两种染色算作一种当 ...

  2. mac下git中文乱码

    今天从window切mac,git使用时各种问题.典型的就是,git commit 可以使用中文注释,但是使用 git log 查看的时候发现都是乱码,乱码效果如下: <B1><E0 ...

  3. HDU 4946 共线凸包

    题目大意: 一些点在一张无穷图上面,每个点可以控制一些区域,这个区域满足这个点到达这个区域的时间严格小于其他点.求哪些点能够控制无穷面积的区域. 题目思路: 速度小的控制范围一定有限. 速度最大当且仅 ...

  4. HDU 4923

    题目大意: 给出一串序列Ai{0,1},求一个序列Bi[0,1](Bi<Bi+1),使得sigama(Ai-Bi)^2最小 思路: 若B相同,则取A的平均数可使方差最小 若B有序,   若A== ...

  5. IIS大数据请求设置方法

    大并发大数据量请求一般会分为几种情况: 1.大量的用户同时对系统的不同功能页面进行查找,更新操作 2.大量的用户同时对系统的同一个页面,同一个表的大数据量进行查询操作 3.大量的用户同时对系统的同一个 ...

  6. asp.net实现GZip压缩和GZip解压

    最近在开发一个网站doc.115sou.com,使用到了GZip压缩技术,经过多次搜索找到asp.net中用GZip对数据压缩和解压缩非常方便,当我第一次拿到这个类的时候却感觉很迷茫,无从下手.主要是 ...

  7. 使用Java VisualVM监控远程JVM

    我们经常需要对我们的开发的软件做各种测试, 软件对系统资源的使用情况更是不可少, 目前有多个监控工具, 相比JProfiler对系统资源尤其是内存的消耗是非常庞大,JDK1.6开始自带的VisualV ...

  8. UVA 821 Page Hopping 网页跳跃(BFS,简单)

    题意: 给一个无权有向图,可认为边的长度为1,求两点间的平均长度(即所有点对的长度取平均),保留3位小数.保证任意点对都可达. 思路: 简单题.直接穷举每个点,进行BFS求该点到其他点的距离.累加后除 ...

  9. Oracle 一次 锁表 处理小记

    同事说测试库上的一张表被锁了. 不能执行DML 操作. 锁表的准确说法应该是阻塞.之前的一遍blog里有说明: 锁 死锁 阻塞Latch 等待 详解 http://blog.csdn.net/tian ...

  10. ECshop 二次开发模板教程4

    今天我们学习一下如何在首页调取某个分类的商品:注意了,这里的修改有一些麻烦了哦:首先你需要下载一套新的模板,比如blueksy 上传到模板目录 /themes/ 也就是 /themes/bluesky ...