新的起點 新的開始

          快樂生活 !

          ADF(ORACLE JEE 平臺)中Table的顯示detail功能的使用

                  ADF(Application development Framework)是Oracle主推的JEE平臺的解決方案,其中包括JDeveloper (開發IDE),Weblogic(Server 容器),ADF Faces(JSF 實現), ADF richFaces(JSF 中擴展組件)等等。
          本文主要討論ADF Faces中,如何控制顯示Table的Details信息。

                  ADF Table類似于JSF標準的Table,但提供許多更有用的功能。比如顯示Datail就是很好的功能,如下圖:用戶可以點擊首列小圖表,查看本行詳細信息
                


          如下圖顯示:

          下面是相對應的JSP和BackingBean

          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
          "http://www.w3.org/TR/html4/loose.dtd">
          <%@ page contentType="text/html;charset=GBK"%>
          <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
          <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
          <%@ taglib uri="http://xmlns.oracle.com/adf/faces" prefix="af"%>
          <%@ taglib uri="http://xmlns.oracle.com/adf/faces/html" prefix="afh"%>
          <f:view>
            
          <afh:html>
              
          <afh:head title="tableTest">
                
          <meta http-equiv="Content-Type" content="text/html; charset=GBK"/>
                
          <style type="text/css">
                body 
          {
          }

                a:link 
          { color: #ffa5a5; }
              
          </style>
              
          </afh:head>
              
          <afh:body>
                
          <h:form>
                  
          <af:table width="98%" value="#{tableTest.allData}" var="data"
                            emptyText
          ="No Data"
                            disclosureListener="#{tableTest.showDetails}"
           banding="none"
                            varStatus
          ="vs">
                    
          <af:column sortable="true" formatType="icon"
                               inlineStyle
          ="border-color:rgb(0,0,0); border-width:thin; margin:auto; text-align:center;">
                      
          <f:facet name="header">
                        
          <af:outputText value="NO."/>
                      
          </f:facet>
                      
          <af:outputText value="#{data.column1}"/>
                    
          </af:column>
                    
          <af:column  inlineStyle="border-color:rgb(0,0,0); border-width:thin; margin:auto; text-align:center;">
                      
          <f:facet name="header">
                        
          <af:outputText value="Last Name"/>
                      
          </f:facet>
                      
          <af:outputText value="#{data.column2}"/>
                    
          </af:column>
                    
          <af:column  inlineStyle="border-color:rgb(0,0,0); border-width:thin; margin:auto; text-align:center;">
                      
          <f:facet name="header">
                        
          <af:outputText value="First Name"/>
                      
          </f:facet>
                      
          <af:outputText value="#{data.column3}"/>
                    
          </af:column>
                    <f:facet name="detailStamp">
                      <af:panelGroup layout="vertical">
                        <af:outputText rendered="#{tableTest.showDetail}"
                                       value="#{data.detail}"/>
                         <af:outputText rendered="#{tableTest.showDetail}"
                                       value="#{data.detail}"/>
                          <af:outputText rendered="#{tableTest.showDetail}"
                                       value="#{data.detail}"/>

                      
          </af:panelGroup>
                    
          </f:facet>
                  
          </af:table>
                
          </h:form>
              
          </afh:body>
            
          </afh:html>
          </f:view>

          其中紅色部分JSP就是顯示Details信息。
          disclosureListener="#{tableTest.showDetails}" 為Table加一個打開關閉Details信息的監聽器,在監聽器里面控制顯示。

          BackBean如下:

          public class TableDataBackBean {
              
          private List allData = new ArrayList();
              
          private boolean showDetail = false
              
          public TableDataBackBean() {
                  TableData tableDate1 
          = new TableData("1","vincent","ma","vincent ma'detail");
                  TableData tableDate2 
          = new TableData("2","barry","fan","barry fan'detail");
                  TableData tableDate3 
          = new TableData("3","jeny","chen","jeny chen'detail");
                  TableData tableDate4 
          = new TableData("4","ross","han","ross han'detail");
                  TableData tableDate5 
          = new TableData("5","robin","liu","robin liu'detail");
                  TableData tableDate6 
          = new TableData("6","walker","liu","walker liu'detail");
                  allData.add(tableDate1);
                  allData.add(tableDate2);
                  allData.add(tableDate3);
                  allData.add(tableDate4);
                  allData.add(tableDate5);
                  allData.add(tableDate6);

              
              }


              public void showDetails(DisclosureEvent disclosureEvent) {
                  if(disclosureEvent.isExpanded()){
                    this.showDetail = true;
                    }

              }


              
          public void setAllData(List allData) {
                  
          this.allData = allData;
              }


              
          public List getAllData() {
                  
          return allData;
              }


              
          public void setShowDetail(boolean showDetail) {
                  
          this.showDetail = showDetail;
              }


              
          public boolean isShowDetail() {
                  
          return showDetail;
              }

          }

          當用戶點擊打開小圖標時,觸發如下事件:
              public void showDetails(DisclosureEvent disclosureEvent) {
                  if(disclosureEvent.isExpanded()){
                    this.showDetail = true;
                    }
              }


          那么,如何只讓它顯示一個Detail 信息呢? 也就是打開第二個時,關閉第一個呢? 很簡單
          修改showDetails方法如下:
              public String oldValue = "";
              
          public void showDetails(DisclosureEvent disclosureEvent) {
                  CoreTable activityTable1 
          = (CoreTable)disclosureEvent.getComponent();
                  
          if(disclosureEvent.isExpanded()){
                    
          this.showDetail = true;
                    }

                    
                  RowKeySet rowKeySet2  
          = activityTable1.getDisclosureState();
                    Set set 
          =rowKeySet2.getKeySet();
                    Iterator iterator 
          = set.iterator();
                    
          if(set.size()==2){
                       
          while(iterator.hasNext()){
                        String temp 
          = (String)iterator.next();
                           System.out.println(
          "Old Value:"+oldValue);
                        System.out.println(
          "Two value:"+temp);
                        
          if(!temp.equals(oldValue)){
                            oldValue 
          = temp;
                            System.out.println(
          "Set Older Value ="+temp);
                            
          break;
                        }

                       }

                       set.clear();
                       set.add(
          new String(oldValue));
                       System.out.println(
          "Display:"+oldValue);
                    }
          else if(set.size()==1){
                        
          while(iterator.hasNext()){
                         String temp 
          = (String)iterator.next();
                             oldValue 
          = temp;
                        }

                        set.add(
          new String(oldValue));
                        System.out.println(
          "only One Display:"+oldValue);
                    }


                    
                   activityTable1.setDisclosureState(rowKeySet2);
              }

          posted on 2009-08-02 21:00 advincenting 閱讀(1655) 評論(1)  編輯  收藏

          評論

          # re: ADF(ORACLE JEE 平臺)中Table的顯示detail功能的使用 2009-08-04 12:23 個性藝術簽名

          斯柯達薩丹哈速度啊隨的  回復  更多評論   


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          公告

          Locations of visitors to this pageBlogJava
        1. 首頁
        2. 新隨筆
        3. 聯系
        4. 聚合
        5. 管理
        6. <2009年8月>
          2627282930311
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          統計

          常用鏈接

          留言簿(13)

          隨筆分類(71)

          隨筆檔案(179)

          文章檔案(13)

          新聞分類

          IT人的英語學習網站

          JAVA站點

          優秀個人博客鏈接

          官網學習站點

          生活工作站點

          最新隨筆

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 临城县| 建平县| 梁河县| 玉林市| 新宾| 西充县| 公安县| 海丰县| 武功县| 循化| 瑞安市| 石楼县| 丹江口市| 塔河县| 五原县| 金沙县| 斗六市| 莱阳市| 托克逊县| 宁乡县| 岑巩县| 元朗区| 临城县| 灌南县| 镇平县| 陇川县| 西藏| 循化| 嘉禾县| 和平县| 莱西市| 全南县| 东山县| 土默特右旗| 平罗县| 潜江市| 诸暨市| 景东| 栾川县| 博野县| 双峰县|