JSF 2 outputText example
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 <
> convert to >
& convert to &
By default, “escape” attribute is set to true.
3. Demo
URL : http://localhost:8080/JavaServerFaces/

JSF 2 outputText example的更多相关文章
- JSF request参数传递
转载自:http://blog.csdn.net/duankaige/article/details/6711044 1:JSF页面之间传参 方法1: <h:outputLink value=& ...
- 关于JSF中immediate属性的总结(二)
The immediate attribute in JSF is commonly misunderstood. If you don't believe me, check out Stack O ...
- JSF标签的使用2
n 事件监听器是用于解决只影响用户界面的事件 Ø 特别地,在beans的form数据被加载和触发验证前被调用 • 用immediate=“true”指明这个行为不触发验证 Ø 在监听器调用 ...
- JSF 与 HTML 标签的联系
*页面的开头 <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%> <%@ t ...
- JSF的ui标签
在使用自己的tag时,首先需要在web.xml里面进行注册,注册方式是在web.xml开头加上: <context-param> <param-name>fac ...
- JSF 2 link, commandLink and outputLink example
In JSF, <h:link />, <h:commandLink /> and <h:outputLink /> tags are used to render ...
- JSF HelloWord
JSF(Java Server Faces)是一种用于构建Web应用程序的新标准Java框架.提供了一种以组件为中心来开发Java Web的用户界面的方法,从而简化了开发. JSF是Java We ...
- JSF开篇之Login案例
开发环境:Myeclipse+JDK5+MyEclipse Tomcat+jsf2.2.8 JSF看起来和STRUTS还是有些像的,刚开始还是遇到一点问题:资源包的存放路径及文件访问路径. 开发Log ...
- JSF 2 textarea example
In JSF, you can use the <h:inputTextarea /> tag to render a HTML textarea field. For example, ...
随机推荐
- mac下app store 无法完成您的购物操作
最近在mac下使用app store 的时候出现提示:“我们无法完成您的购物操作 网络连接已中断”.但是我的网络是好的,图片如下: 网上找了各种解决办法,比如将DNS改成 114.114.114.11 ...
- EXT 数据按F12,F11 显示问题
最近做关于EXT的项目,因为是刚开始接触EXT,对什么都不熟悉,所以把其他人写好的浏览页代码考过了来,换成自己需要的. 一切都做好了,然后数据不出来,就调试看,后台也出现数据了,然后就按F12调试前台 ...
- 基于XMPP的即时通信系统的建立(一)— XMPP基础概念
相关背景 IM(Instant Messaging)正在被广泛使用,特别是公司与它们的客户互动连接方案以及互联网与Web2.0相关的应用.为了解决即时通信的标准问题,IETF(互联网工程任务组 The ...
- UVa 11732 (Tire树) "strcmp()" Anyone?
这道题也是卡了挺久的. 给出一个字符串比较的算法,有n个字符串两两比较一次,问一共会有多少次比较. 因为节点会很多,所以Tire树采用了左儿子右兄弟的表示法来节省空间. 假设两个不相等的字符串的最长公 ...
- 《分销系统-原创第一章》之“多用户角色权限访问模块问题”的解决思路( 位运算 + ActionFilterAttribute )
此项目需求就是根据给用户分配的权限,进行相应的权限模块浏览功能,因为项目不是很大,所以权限没有去用一张表去存,我的解决思路如下,希望大家给点建议. 数据库用户表结构如下: 数据库表梳理: BankUs ...
- [反汇编练习] 160个CrackMe之015
[反汇编练习] 160个CrackMe之015. 本系列文章的目的是从一个没有任何经验的新手的角度(其实就是我自己),一步步尝试将160个CrackMe全部破解,如果可以,通过任何方式写出一个类似于注 ...
- HDU 5303 Delicious Apples 美味苹果 (DP)
题意: 给一个长为L的环,起点在12点钟位置,其他位置上有一些苹果,每次带着一个能装k个苹果的篮子从起点出发去摘苹果,要将全部苹果运到起点需要走多少米? 思路: 无论哪处地方,只要苹果数超过k个,那么 ...
- android和ios流媒体库推荐
1基本信息编辑 Vitamio是一款 Android 与 iOS 平台上的全能多媒体开发框架,全面支持硬件解码与 GPU 渲染.从2011年8月上线到2014年1月,Vitamio 凭借其简洁易用的 ...
- DataGuard相同SID物理Standby搭建
Oracle Data Guard 是针对企业数据库的最有效和最全面的数据可用性.数据保护和灾难恢复解决方案.它提供管理.监视和自动化软件基础架构来创建和维护一个或多个同步备用数据库,从而保护数据不受 ...
- java 中的Exception RuntimeException 区别
在java的异常类体系中: 1.Error和RuntimeException是非检查型异常,其他的都是检查型异常; 2.所有方法都可以在不声明throws的情况下抛出RuntimeException及 ...