zoukankan      html  css  js  c++  java
  • 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 &lt;
            > convert to &gt;
            & convert to &amp;
    

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

    3. Demo

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

    jsf2-outputtext-example

  • 相关阅读:
    [ACM] POJ 3687 Labeling Balls (拓扑排序,反向生成端)
    xml和json选择奖
    android 如何分析java.lang.IllegalArgumentException: Cannot draw recycled bitmaps异常
    代码农民提高生产力
    &#39;Basic&#39; attribute type should not be a persistence entity/a container
    13 适配器
    密码学基础知识(四)分组密码
    PKCS #1 RSA Encryption Version 1.5 填充方式
    rsa加密--选择padding模式需要注意的问题。。。
    RSA PKCS1 填充方式
  • 原文地址:https://www.cnblogs.com/ghgyj/p/4765391.html
Copyright © 2011-2022 走看看