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, ...
随机推荐
- Windows 7下配置JDK环境变量,JAVA环境变量配置,Tomcat服务器的使用
参考来源: http://www.cnblogs.com/pannysp/archive/2012/03/07/2383364.html 1. 常识: 1.1 War包 War包一般是在进行Web开发 ...
- 1156. Two Rounds(dfs+背包)
1156 求出每个联通块的黑白块数 然后再背包 二维的背包 要保证每个块都得取一个 写的有些乱.. #include <iostream> #include<cstdio> # ...
- Parallel WebDriver executions using TestNG
In this post, we will see how does one make use of TestNG to kick off parallel UI tests using WebDri ...
- 结构体mem_pool_t
/** Memory area header */ typedef struct mem_area_struct mem_area_t; /** Memory pool */ typedef stru ...
- c#里面的namespace基础(一)
我现在感到学好C#就是就是要知道,C#的基本语法,C#的新的特点,C#能干什么! 其中我感到不管如何,NAMESPACE都是很关键的,可以说不是只对C#而言,而是整个.NET都是由NAMESPACE组 ...
- WIN7开无线
可以的,WIN7自身就带有这个功能的,不过默认是不开启的,也可以下载一个软件来弄.1.请却仍您使用的操作系统是微软的Windows 7或者Windows server 2008 R2,正版盗版皆可.( ...
- OpenGL 顶点缓存对象
顶点缓存对象(Vertex Buffer Object,简称 VBO),允许开发者根据情况把顶点数据放到显存中. 如果不用 VBO,用 glVertexPointer / glNormalPointe ...
- DrawDibDraw函数的使用方法
使用windows的的自带的函数来显示图像可能始终还是绕不开两个概念, 视口和窗口. 视口--- 屏幕上的一个显示用的矩形框. 窗口--- 完整图像上的一个用于取数的矩形框. 屏幕的宽度.高度和视口参 ...
- directdraw显示yuv视频,出现屏保时,yuv显示不出来,表面丢失
原因是: DDrawSurface 丢失, DDraw表面在很多情况下都会丢失(如:启动其他全屏独占程序,屏保,或锁屏时), 表面丢失其实就是表面所使用的内存或显存被DirectDraw系统释放, 分 ...
- ORACLE 远程连接数据库
通过运行->cmd->sqlplus/nolog 登录sqlplus时,突然间提示“sqlplus不是内部或外部命令,也不 是可运行的程序或批处理文件”,如下图: 分析后感觉不可能啊,因为 ...