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, ...
随机推荐
- sharepoint Linq方式的增,删,查,改
Site9527EntitiesDataContext (重要的类):连接实体与网站List操作 SPContext.Current.Web.Url:获取当前操作的页面 FirstOrDefault: ...
- apache开源项目 -- Tuscany
tuscany是Apache组织关于SOA实现的一个开放源码的工程项目,目前处于孵化期阶段. 该项目主要基于SCA,SDO,DAS等技术上实现的. SCA 的基本概念以及 SCA 规范的具体内容并不在 ...
- 调用DirectDraw接口和调DirectDraw7接口的不同点对比
调用DirectDraw接口步骤: 1. 包含链接库ddraw.lib 2. 初始化窗口类型(全屏独占时类型用popup). 3. 在初始化窗口后初始化Direct ...
- Sourcetree add Submodule
LMXMN041:ximalaya will.wei$ git submodule add https://github.com/willbin/WeLib02.git Submodule Cloni ...
- 【转】iOS-延迟操作方法总结
原文网址:http://lysongzi.com/2016/01/30/iOS-%E5%BB%B6%E8%BF%9F%E6%93%8D%E4%BD%9C%E6%96%B9%E6%B3%95%E6%80 ...
- Solr与Mysql简单集成
Solr与Mysql数据库的集成,实现全量索引.增量索引的创建. 基本原理很简单:在Solr项目中注册solr的DataImportHandler并配置Mysql数据源以及数据查询sql语句.当我们通 ...
- 滑屏 H5 开发实践九问
滑屏的交互形式自从在 H5 中流行起来,便广泛应用在产品宣传.广告.招聘和活动运营等场景中,作为微信朋友圈广告惯用的形式,其影响力更是得到了强化与放大.如今滑屏H5可谓玲琅满目,数不尽数. 作为一个 ...
- replace() MySQL批量替换指定字段字符串
mysql replace实例说明: UPDATE tb1 SET f1=REPLACE(f1, 'abc', 'def'); REPLACE(str,from_str,to_str) 在字符串 st ...
- User Agent
Android: Mozilla/5.0 (Linux; U; Android 2.3.5; zh-cn; MI-ONE Plus Build/GINGERBREAD) AppleWebKit/533 ...
- linux命令——磁盘管理cd
Linux cd 命令可以说是Linux中最基本的命令语句,其他的命令语句要进行操作,都是建立在使用 cd 命令上的. cd指令可让用户在不同的目录间切换,但该用户必须拥有足够的权限进入目的目录. 1 ...