JSF、Richfaces学习

http://wenku.baidu.com/link?url=2vQ4d4SoRVorLmbRLWlgyanScSDFLph_oTwHyUZJQJx_lYmBWJlpidjMQoBUDnEFnfuxxqXXYDhEm-U8PzKrr4OQ_GLUvUkhsApmXr2eW0a

http://blog.csdn.net/sonikk/article/details/9875239


用richfaces标签实现页面定时刷新功能 - [richfaces]

2009-07-30

版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://www.blogbus.com/hysheart-logs/43212009.html

一句话即可,reRender="table" 表示要刷新的页面ID.interval代表多少时间刷新一次,600000等于一分钟,1000等于一秒.

<a4j:poll interval="600000" reRender="table"></a4j:poll>



通过这个demo,可以理解richfaces的基本运行方式,对该技术有一个感性认识。

其中有ajax标签,可以自动同步数据到服务器端,方便开发人员,当然用得不好,也可能造成性能低下的问题!


演示效果:


1.输入框当中默认是5


2.修改为8

3. 右边的菜单会自动更新成8个选项

选中option3后,会出现如下日志输入:



官方文档:

http://docs.jboss.org/richfaces/latest_4_X/vdldoc/a4j/ajax.html


TestBean.java

[java]  view plain copy
  1. package com.ccbupt.kaoshi.xuanze;  
  2.   
  3. import java.io.Serializable;  
  4. import java.util.ArrayList;  
  5. import java.util.List;  
  6.   
  7. import javax.annotation.PostConstruct;  
  8. import javax.faces.bean.ManagedBean;  
  9. import javax.faces.bean.ManagedProperty;  
  10. import javax.faces.bean.SessionScoped;  
  11. import javax.faces.event.ValueChangeEvent;  
  12. import javax.faces.model.SelectItem;  
  13. import org.richfaces.demo.tables.model.capitals.Capital;  
  14. import com.ccbupt.kaoshi.service.UserRoleService;  
  15.   
  16. @ManagedBean(name="testBean")  
  17. @SessionScoped  
  18. public class TestBean implements Serializable{  
  19.   
  20.     private static final long serialVersionUID = 1109360897806292248L;  
  21.     private List<SelectItem> capitalsOptions = null;  
  22.     private String value = "";  
  23.     private int count = 5;  
  24.       
  25.     /**@ManagedProperty(value="userRoleServices") 
  26.     private UserRoleService userRoleService; 
  27.     */  
  28.       
  29.       
  30.     @PostConstruct  
  31.     public void init() {  
  32.         capitalsOptions = new ArrayList<SelectItem>();  
  33.         //System.out.println(count);  
  34.         for(int i = 0; i < count; i++) {  
  35.             capitalsOptions.add(new SelectItem(i,"option"+i));  
  36.         }  
  37.     }  
  38.       
  39. /*  public void valueChanged(ValueChangeEvent event) { 
  40.         capitalsOptions.clear(); 
  41.         System.out.println(count); 
  42.         if (null != event.getNewValue()) { 
  43.             capitalsOptions = new ArrayList<SelectItem>(); 
  44.             for (int i = 0; i < count; i++) { 
  45.                 capitalsOptions.add(new SelectItem("1","二")); 
  46.             } 
  47.         } 
  48.     } 
  49. */    
  50.     public List<SelectItem> getCapitalsOptions() {  
  51.         return capitalsOptions;  
  52.     }  
  53.   
  54.     public void setCapitalsOptions(List<SelectItem> capitalsOptions) {  
  55.         this.capitalsOptions = capitalsOptions;  
  56.     }  
  57.   
  58.     public String getValue() {  
  59.         return value;  
  60.     }  
  61.   
  62.     public void setValue(String value) {  
  63.         this.value = value;  
  64.     }  
  65.   
  66. /** public UserRoleService getUserRoleService() { 
  67.         return userRoleService; 
  68.     } 
  69.  
  70.     public void setUserRoleService(UserRoleService userRoleService) { 
  71.         this.userRoleService = userRoleService; 
  72.     } 
  73. */  
  74.     public void getTiJiao() {  
  75.         System.out.println(value + "已被选中" + count);  
  76.     }  
  77.       
  78.     public int getCount() {  
  79.         return count;  
  80.     }  
  81.       
  82.     public void setCount(int count) {  
  83.         capitalsOptions.clear();  
  84.         for (int i = 0; i < count; i++) {  
  85.             capitalsOptions.add(new SelectItem(i,"option"+i));  
  86.         }  
  87.           
  88.         this.count = count;  
  89.     }  
  90.           
  91. }  


test.html
[html]  view plain copy
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml"  
  3.     xmlns:ui="http://java.sun.com/jsf/facelets"  
  4.     xmlns:h="http://java.sun.com/jsf/html"  
  5.     xmlns:f="http://java.sun.com/jsf/core"  
  6.     xmlns:a4j="http://richfaces.org/a4j"  
  7.     xmlns:rich="http://richfaces.org/rich">  
  8.   
  9. <h:head>  
  10.     <link  
  11.         href="${facesContext.externalContext.requestContextPath}/css/source.css"  
  12.         rel="stylesheet" type="text/css" />  
  13.     <style type="text/css">  
  14.             body {  
  15.                 background-image:  
  16.                     url(${facesContext.externalContext.requestContextPath}/images/page_bg.gif)  
  17.                     ;  
  18.             }  
  19.             </style>  
  20. </h:head>  
  21.     <div style="test-align: center;">  
  22.         <h:form>  
  23.               
  24.             <h:panelGrid columns="2" border="0" cellpadding="0" cellspacing="0"  
  25.                 columnClasses="vertical-align-top" style="bgcolor:red;">  
  26.                 <h:column>  
  27.                   
  28.                 </h:column>  
  29.                 <h:column>  
  30.                     <h:panelGrid columns="6" border="0" cellpadding="0" cellspacing="0"  
  31.                         columnClasses="vertical-align-top" style="bgcolor:red;"  
  32.                         styleClass="login_layout">  
  33.                           
  34.                         <h:inputText value="#{testBean.count}" >  
  35.                             <a4j:ajax event="keyup" render="second" />  
  36.                         </h:inputText>  
  37.                           
  38.                         <a4j:outputPanel id="second" layout="block">  
  39.                             <rich:select value="#{testBean.value}" render="yiXuan">  
  40.                                 <f:selectItems value="#{testBean.capitalsOptions}" />  
  41.                             </rich:select>  
  42.                         </a4j:outputPanel>  
  43.                           
  44.                         <h:commandButton action="#{testBean.getTiJiao}" value="提交"  
  45.                             style="width:50pt;color:blue;"></h:commandButton>  
  46.                               
  47.                         <h:outputText id="yixuan" style="width:50pt;color:red;"  
  48.                             value="#{textBean.value}"></h:outputText>  
  49.                               
  50.                     </h:panelGrid>  
  51.                 </h:column>  
  52.             </h:panelGrid>  
  53.               
  54.         </h:form>  
  55.     </div>  
  56.   
  57. <h:body>  
  58.   
  59.   
  60.   
  61.   
  62. </h:body>  
  63.   
  64. </html>  


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值