posts - 40,  comments - 187,  trackbacks - 0
          說(shuō)在前面的話:
          ECSide組件,一個(gè)功能豐富,簡(jiǎn)單易用的列表組件,套用圈子里的一句話:它可能不是最好的,但也許是你最需要的。感興趣的同志們可以訪問(wèn)ECSide的圈子,里面的資源及文檔都很豐富,不在這里做過(guò)多的介紹了,圈子地址為http://ecside.group.javaeye.com/
          ?
          實(shí)例講解:
          實(shí)現(xiàn)從一張公告表讀取公告信息并以列表展示的功能。本文中的源代碼可通過(guò)這個(gè)鏈接下載。
          bulletin_powered_by_ecside_allen.zip

          另附ECSide標(biāo)簽的使用說(shuō)明,方便大家查閱。

          ECSide標(biāo)簽使用說(shuō)明

          開發(fā)環(huán)境:
          Dev Tool: Eclipse 3.3
          Web Server: Tomcat 5.5.23
          Framework: Spring 2.0.6 + Hibernate 3.3.0 + Struts 1.2.8 + ecside_2.0_RC1
          Database: Oracle 9i
          ?
          實(shí)現(xiàn)步驟:

          0) 準(zhǔn)備工作

          使用ecside工具,你需要準(zhǔn)備的有:

          1、ecside.jar

          2、 ecside.tld標(biāo)簽

          3、ecside.js

          4、ecside.css

          5、ecside使用table圖片

          注:以上內(nèi)容均可在圈子中下載到。

          1)配置ecside
          ?? 需要在web.xml中配置ecside的過(guò)濾器,用于文件導(dǎo)出和語(yǔ)言編碼,忘記配置的話,會(huì)出現(xiàn)“正在提交”的問(wèn)題。
          <!-- ?ecside?export?filter? -->
          ????
          < filter >
          ????????
          < filter-name > ecsideExport </ filter-name >
          ????????
          < filter-class > org.ecside.filter.ECSideFilter </ filter-class >
          ????????
          < init-param >
          ????????????
          < param-name > useEasyDataAccess </ param-name >
          ????????????
          < param-value > true </ param-value >
          ????????
          </ init-param >
          ????????
          < init-param >
          ????????????
          < param-name > useEncoding </ param-name >
          ????????????
          < param-value > true </ param-value >
          ????????
          </ init-param >
          ????????
          < init-param > ????????
          ????????????
          < param-name > encoding </ param-name >
          ????????????
          < param-value > UTF-8 </ param-value >
          ????????
          </ init-param >
          ????
          </ filter >
          ????
          < filter-mapping >
          ????????
          < filter-name > ecsideExport </ filter-name >
          ????????
          < url-pattern > /* </ url-pattern >
          ????
          </ filter-mapping >

          還需配置一下tld,
          ?
          < taglib >
          ?????????
          < taglib-uri > /WEB-INF/ecside.tld </ taglib-uri >
          ????????
          < taglib-location > /WEB-INF/taglib/ecside.tld </ taglib-location >
          ????
          </ taglib >
          ?
          另外,還可以初始化ecside.properties文件,寫這個(gè)文件的目的是:把公共的內(nèi)容集中在一個(gè)文件中,方便使用。一旦我們使用ecside 組件,哪個(gè)這些配置信息就可以直接引用。形式可以如下:
          ###########????????table???????###############
          table.method=post
          table.width=95%
          table.pageSizeList=10,20,50,100,1000,2000,all
          table.rowsDisplayed=10
          table.sortable=true
          ###########????????column??????###############
          column.format.date=yyyy/MM/dd
          column.format.number=0.##
          column.format.currency=###,###,###

          2) 在Struts Action中使用ecside
          首先來(lái)簡(jiǎn)單介紹一下RSF(列表、排序、過(guò)濾)操作方式:
          ecside支持兩種RSF方式:?? 基于java collection層 和 基于數(shù)據(jù)庫(kù)層,下面分別介紹:

          基于java collection層
          這是ec的默認(rèn)實(shí)現(xiàn)方式, 最簡(jiǎn)單易用.你要做的就是將整個(gè)列表所要展現(xiàn)的全部數(shù)據(jù)放入collection 內(nèi),并交給EC來(lái)處理.其中RSF操作,全部由EC在內(nèi)存中完成,由于你已經(jīng)將全部數(shù)據(jù)放入了collection中,所以排序 過(guò)濾都是基于全部數(shù)據(jù)的.你要在DAO中做的就是一個(gè) 查詢操作,SQL語(yǔ)句中不需要加入 關(guān)于排序 分頁(yè) 過(guò)濾的代碼.
          這種方式的優(yōu)點(diǎn)非常明顯:實(shí)現(xiàn)簡(jiǎn)單.缺點(diǎn)同樣明顯,而且在很大程度上是致命的: 數(shù)據(jù)量大的時(shí)候速度慢,而且很可能OutOfMemory.
          ?
          基于數(shù)據(jù)庫(kù)層
          在這種方式下,EC的角色發(fā)生了一點(diǎn)點(diǎn)變化。此時(shí),EC負(fù)責(zé)把 collection 里的內(nèi)容展現(xiàn)出來(lái), 同時(shí)會(huì)向你提供RSF相關(guān)的參數(shù)。而這些參數(shù)需要你自己手動(dòng)取得 并傳入到DAO中(當(dāng)然EC提供了很多方便的方法來(lái)幫助你取得這些參數(shù)),具體功能的實(shí)現(xiàn)需要你自己在DAO中組織相應(yīng)的SQL語(yǔ)句。
          這種方式的優(yōu)缺點(diǎn)正好和方式一相反。
          ?
          我這里采用第二種基于數(shù)據(jù)庫(kù)層的分頁(yè)方式實(shí)現(xiàn)列表,這時(shí)在JSP中使用ecside時(shí),要將<ec:table>中的幾個(gè)重要屬性設(shè)定為limit。如: <ec:table filterRowsCallback="process/limit"? sortRowsCallback="process/limit"? retrieveRowsCallback="process/limit" ...> 這里filterRowsCallback表示過(guò)濾的Callback方式,sortRowsCallback表示排序的Callback方式,retrieveRowsCallback表示分頁(yè)的Callback方式,這三個(gè)屬性都需要設(shè)定為limit。(不熟悉的讀者可以查詢?cè)鍱C中的相關(guān)說(shuō)明,不在這里詳述。)
          Struts Action的代碼為:
          /* ?
          ?????*?用ECSide構(gòu)建列表
          ??????*
          ?????
          */

          ????
          public ?ActionForward?list(ActionMapping?mapping,?ActionForm?form,
          ????????????HttpServletRequest?request,?HttpServletResponse?response)?
          {
          ????????String?v_type?
          = ?request.getParameter( " type " );
          ????????
          // 0)?設(shè)定過(guò)濾條件
          ????????Map < String,?Object > ?filterMap? = ? new ?HashMap < String,?Object > ();
          // ????????filterMap.put("content",?"test");
          ????????Map < String,?Object > ?sortMap? = ? new ?HashMap < String,?Object > ();
          ????????sortMap.put(
          " createTime " ,? " desc " );? // ?按照創(chuàng)建時(shí)間倒序排列
          ????????
          // 1)?設(shè)定ECSide分頁(yè)對(duì)象
          ????????Limit?limit? = ?RequestUtils.getLimit(request);
          ????????
          // ?取總記錄數(shù)
          ???????? int ?pageNo? = ?RequestUtils.getPageNo(request);
          ????????
          int ?pagesize? = ?RequestUtils.getCurrentRowsDisplayed(request);
          ????????
          if ?(pagesize? == ? 0 )
          ????????????pagesize?
          = ?PAGESIZE;
          ????????
          // ?設(shè)置總記錄數(shù)及每頁(yè)記錄數(shù)
          ???????? int ?totalRows? = ?RequestUtils.getTotalRowsFromRequest(request);
          ????????
          if ?(totalRows? <= ? 0 )? {
          ????????????totalRows?
          = ?getEntityManager()
          ????????????????????.getCount(getEntityClass(),?filterMap);
          ????????}

          ????????limit.setRowAttributes(totalRows,?pagesize);
          ????????
          // ?根據(jù)參數(shù)得到結(jié)果
          ????????List < Bulletin > ?result? = ?getEntityManager().queryForListByCriter(
          ????????????????getEntityClass(),?filterMap,?sortMap,
          ????????????????((pageNo?
          - ? 1 )? * ?pagesize),?pagesize);
          ????????request.setAttribute(getEntityListName(),?result);
          ????????request.setAttribute(
          " myPageSize " ,?getPageSize(request));
          ????????request.setAttribute(
          " type " ,?v_type);
          ????????
          return ?mapping.findForward(LIST);
          ????}

          這里我構(gòu)建了過(guò)濾條件及排序條件查詢數(shù)據(jù),通過(guò)queryForListByCriter方法,輸入當(dāng)前起始頁(yè)及每頁(yè)的顯示條數(shù)在數(shù)據(jù)層得到所需數(shù)據(jù)。詳見代碼中的注釋。另附數(shù)據(jù)處理層兩個(gè)方法的代碼:
          /*分頁(yè)查詢數(shù)據(jù)*/
          public?List?queryForListByCriter(Class?entityClass,?Map?filter,
          ????????????Map?sortMap,?
          int?start,?int?everypage)?{
          ????????Criteria?criteria?
          =?getCriteria(entityClass);
          ????????setFilter(criteria,?filter);
          ????????setSort(criteria,?sortMap);
          ????????criteria.setFirstResult(start);
          ????????criteria.setMaxResults(everypage);
          ????????
          return?criteria.list();
          ????}


          /*計(jì)算數(shù)據(jù)條數(shù)*/????
          public?int?getCount(Class?entityClass,?Map?filter)?{
          ????????Criteria?criteria?
          =?getCriteria(entityClass);
          ????????setFilter(criteria,?filter);
          ????????criteria.setProjection(Projections.rowCount());
          ????????
          return?((Integer)?criteria.uniqueResult()).intValue();
          ????}

          注:ecside與ORM工具無(wú)關(guān),不管你使用什么方法只要能獲得一個(gè)集合就好,這里我用的是Hibernate獲得的集合。
          ?
          3)在JSP中使用ecside
          需要注意的是:
          1. items的值一定要和request.setAttribute(getEntityListName(), result); 屬性一致
          2. 可以引用屬性名做為值顯示,如:${bulletin.id}
          3. <ec:column property="name" title="公告名稱">property屬性值一定是映射文件中的某個(gè)屬性
          <% @?page?contentType = " text/html;?charset=UTF-8 " ? %>
          <% @?taglib?uri = " /WEB-INF/ecside.tld " ?prefix = " ec " ? %>
          <% @?taglib?uri = " http://java.sun.com/jsp/jstl/core " ?prefix = " c " ? %>
          <% @?taglib?uri = " http://java.sun.com/jsp/jstl/fmt " ?prefix = " fmt " ? %>
          <% @?taglib?uri = " http://java.sun.com/jsp/jstl/functions " ?prefix = " fn " ? %>
          < c:set? var ="ctx" ?value ="${pageContext.request.contextPath}" />

          < html >
          < head >
          ????
          < meta? http-equiv ="Content-Type" ?content ="text/html;?charset=UTF-8" ? />
          ?????
          < META? HTTP-EQUIV ="pragma" ?CONTENT ="no-cache" >
          ????
          < META? HTTP-EQUIV ="Cache-Control" ?CONTENT ="no-cache,?must-revalidate" >
          ????
          < META? HTTP-EQUIV ="expires" ?CONTENT ="0" >
          ????
          < title > 公告列表 </ title >
          ????
          < link? rel ="stylesheet" ?type ="text/css" ?href ="${ctx}/module/bizAcceptance/resources/ecside/css/ecside_style.css" ? />
          ????
          < script? type ="text/javascript" ?src ="${ctx}/module/bizAcceptance/resources/ecside/js/prototype_mini.js" ? ></ script > ????
          ????
          < script? type ="text/javascript" ?src ="${ctx}/module/bizAcceptance/resources/ecside/js/ecside.js" ? ></ script >
          ????
          < script? type ="text/javascript" ?src ="${ctx}/module/bizAcceptance/resources/ecside/js/ecside_msg_utf8_cn.js" ? ></ script >
          </ head >
          < body >
          < table? width ="100%" ??border ="0" ?cellspacing ="0" ?cellpadding ="0" >
          <!-- ?校驗(yàn)信息? -->
          ??
          < tr >
          ????
          < td? class ="left" > <% @?include?file = " /module/commons/htmlmessages.jsp " ? %> </ td > ????????????????
          ??
          </ tr >
          ??
          < tr >
          ????????
          < td? height ="30" >
          ????????????
          < span? style ="align:left;font-size:9pt;" >
          ????????????????請(qǐng)選擇公告
          ??????????????
          < input? type ="button" ?name ="Submit3" ?value ='進(jìn)? 入'?onclick ="doView()" >
          ????????????
          </ span >< br >
          ????????
          </ td >
          ??
          </ tr >
          ??
          < tr >
          ??????
          < td >
          ??????????
          < ec:table? items ="bulletins" ?var ="bulletin"
          ????????????retrieveRowsCallback
          ="limit"
          ????????????filterRowsCallback
          ="limit" ???
          ????????????action
          ="${ctx}/module/bulletin.do?method=list&type=${type}"
          ????????????title
          ="我的公告列表" ?
          ????????????useAjax
          ="false"
          ????????????showPrint
          ="false"
          ????????????width
          ="100%"
          ????????????resizeColWidth
          ="true"
          ????????????filterable
          ="false"
          ????????????listWidth
          ="100%"
          ????????????rowsDisplayed
          ="${myPageSize}"
          ????????????pageSizeList
          ="${myPageSize},10,15,20,all"
          ????????????xlsFileName
          ="公告列表.xls"
          ????????????styleClass
          ="tableRegion" ?
          ????????????style
          ="border:2px;table-layout:fixed;"
          ????????????classic
          ="true" >
          ????????????
          < ec:row >
          ????????????????
          < ec:column? property ="_0" ?title ="選擇" ?width ="6%" >
          ????????????????????
          < input? type ="radio" ?id ="radio_${GLOBALROWCOUNT}" ?name ="checkedRadio" ?value ="${bulletin.id}" >
          ????????????????
          </ ec:column >
          ????????????????
          < ec:column? property ="_1" ?title ="序號(hào)" ?width ="6%" >
          ????????????????????${GLOBALROWCOUNT}
          ????????????????
          </ ec:column >
          ????????????????
          < ec:column? property ="name" ?title ="公告名稱" >
          ????????????????????
          < a? href ="JavaScript:doStarting('${affair.id}')" ?title ="點(diǎn)擊查看" >< c:out? value ="${bulletin.name}" /></ a >
          ????????????????
          </ ec:column >
          ????????????????
          < ec:column? property ="desn" ?title ="描述" ?ellipsis ="true" ? />
          ????????????????
          < ec:column? property ="createBy" ?title ="創(chuàng)建人" ?width ="10%" ? />
          ????????????????
          < ec:column? property ="createTime" ?title ="創(chuàng)建時(shí)間" ??width ="20%" >
          ????????????????????
          < fmt:formatDate? value ="${bulletin.createTime}" ?pattern ="yyyy-MM-dd?HH:mm:ss" /> &nbsp;
          ????????????????
          </ ec:column >
          ????????????????
          < ec:column? property ="_2" ?title ="可執(zhí)行操作" >
          ????????????????????
          < a? href ="${ctx}/module/bulletin.do?method=edit&ID=${bulletin.id}" >< img? src ="${ctx}/images/affairmgt/update.gif" ?border ="0" ?title ="編輯" > 編輯 </ a > &nbsp;
          ????????????????????
          < a? href ="${ctx}/module/bulletin.do?method=delete&ID=${bulletin.id}" >< img? src ="${ctx}/images/affairmgt/delete.gif" ?border ="0" ?title ="移除" > 移除 </ a >
          ????????????????
          </ ec:column >
          ????????????
          </ ec:row >
          ????????
          </ ec:table >
          ??????
          </ td >
          ??
          </ tr > ??
          </ table >
          < script? language ="javascript" >
          ????
          var ?_confirm? = ? " false " ;
          ????
          var ?confirmMsg? = ? " 查看此公告? " ;
          ????
          var ?urlPrefix? = ? " ${ctx}/module/bulletin.do?method=view&ID= " ;
          ????
          function ?doView(itemId)? {
          ??????????
          if ?(itemId? != ? null )? {
          ????????????
          if ?(_confirm? == ?' false '? || ?confirm(confirmMsg))? {
          ????????????????ShowWaiting('正在加載數(shù)據(jù),請(qǐng)稍候');
          ??????????????????window.location?
          = ?urlPrefix? + ?itemId;
          ????????????}

          ??????????}
          ? else ? {
          ??????????????
          var ?radio? = ?document.getElementsByName('checkedRadio');
          ??????????????
          for ?(i? = ? 0 ;?i? < ?radio.length;?i ++ )? {
          ??????????????????
          if ?(radio[i].checked)? {
          ????????????????????
          if ?(_confirm? == ?' false '? || ?confirm(confirmMsg))? {
          ????????????????????????itemId?
          = ?radio[i].value;
          ??????????????????????????ShowWaiting('正在加載數(shù)據(jù),請(qǐng)稍候');
          ??????????????????????????window.location?
          = ?urlPrefix? + ?itemId;
          ????????????????????}

          ????????????????????
          return ;
          ??????????????????}

          ??????????????}

          ??????????????alert('請(qǐng)選擇一個(gè)公告!');
          ??????????}

          ???}

          </ script >
          ??
          </ body > ?
          </ html >
          ?

          其中,<ec:column property="desn" title="描述" ellipsis="true" />,ellipsis屬性實(shí)現(xiàn)單元格內(nèi)數(shù)據(jù)過(guò)長(zhǎng)的時(shí)候,自動(dòng)截短并加"..."的功能,但是ie only!因?yàn)閒f不支持 text-overflow: ellipsis; 使用ellipsis="true"的同時(shí),還要為ec:table加上 style="table-layout:fixed;" (如果您已經(jīng)使用了調(diào)整列寬功能 則不用添加)。

          ?
          4) 啟動(dòng)服務(wù),大功告成。?

          ecside_list.jpg?


          需要提醒一下,這里采用的是ECSide的默認(rèn)樣式,可根據(jù)您具體的需求改變樣式文件。


          ?????????????????????????????????????????????????????????????????????????????????????THE END
          posted on 2008-12-15 10:47 小立飛刀 閱讀(9174) 評(píng)論(10)  編輯  收藏 所屬分類: User Interface

          FeedBack:
          # re: 如何使用ECSide(GT-Grid)組件構(gòu)建列表(內(nèi)附源碼)[未登錄]
          2008-12-16 11:16 | 老馬
          我靠 寫的不錯(cuò)呀  回復(fù)  更多評(píng)論
            
          # re: 如何使用ECSide(GT-Grid)組件構(gòu)建列表(內(nèi)附源碼)
          2008-12-16 14:02 | 小立飛刀
          更新ecside Jar包的版本為ecside_2.0_RC1.jar  回復(fù)  更多評(píng)論
            
          # re: 如何使用ECSide(GT-Grid)組件構(gòu)建列表(內(nèi)附源碼)
          2009-01-13 14:06 | 小立飛刀
          解決使用xlsFileName進(jìn)行excel導(dǎo)出,無(wú)法導(dǎo)出全部數(shù)據(jù)的問(wèn)題

          在采用基于數(shù)據(jù)層的分頁(yè)、過(guò)濾、排序方式時(shí),導(dǎo)出操作也會(huì)采用相同的方式處理,即ecside會(huì)調(diào)用< ec:table>的action屬性定義的方法進(jìn)行導(dǎo)出數(shù)據(jù)封裝,這就造成了導(dǎo)出時(shí)無(wú)法導(dǎo)出全部數(shù)據(jù)而只是導(dǎo)出當(dāng)前頁(yè)面數(shù)據(jù)。

          解決方法是在action中封裝結(jié)果數(shù)據(jù)時(shí)處理一下導(dǎo)出的操作,取全部數(shù)據(jù),通過(guò)limit.isExported()判斷,代碼如下:
          if (limit.isExported()) //判斷操作是否為導(dǎo)出 若是則封裝全部結(jié)果數(shù)據(jù)
          result = getEntityManager().findForListByFilter(
          filter, 0, totalRows);
          else
          result = getEntityManager().findForListByFilter(
          filter, ((pageNo - 1) * pagesize), pagesize);   回復(fù)  更多評(píng)論
            
          # re: 如何使用ECSide列表組件構(gòu)建列表(內(nèi)附源碼)
          2009-03-09 10:43 | philip
          是否支持jstl標(biāo)簽  回復(fù)  更多評(píng)論
            
          # re: 如何使用ECSide列表組件構(gòu)建列表(內(nèi)附源碼)
          2009-03-09 15:41 | 小立飛刀
          @philip
          支持的 我給的例子中就用了 比如可以如下使用<fmt:formatDate>標(biāo)簽:

          <ec:column property ="createTime" title ="創(chuàng)建時(shí)間">
          <fmt:formatDate value ="${bulletin.createTime}" pattern ="yyyy-MM-dd HH:mm:ss" />
          </ec:column>

          但是好像不能作為屬性使用
            回復(fù)  更多評(píng)論
            
          # re: 如何使用ECSide列表組件構(gòu)建列表(內(nèi)附源碼)
          2009-11-01 15:21 | 剛學(xué)ecside
          import net.allen.core.struts.StrutsEntityAction;
          大哥,這個(gè)類沒有啊
          能不能弄全一點(diǎn)啊,不勝感激!
          我QQ:417186803  回復(fù)  更多評(píng)論
            
          # re: 如何使用ECSide列表組件構(gòu)建列表(內(nèi)附源碼)
          2009-11-03 10:04 | 小立飛刀
          @剛學(xué)ecside
          這個(gè)類并無(wú)特殊用途,如果您用的是struts1.2的話,完全可以繼承DispatchAction。  回復(fù)  更多評(píng)論
            
          # re: 如何使用ECSide列表組件構(gòu)建列表(內(nèi)附源碼)[未登錄]
          2009-11-19 11:25 | xx
          請(qǐng)問(wèn)用ecside組件時(shí),實(shí)現(xiàn)對(duì)列數(shù)據(jù)的編輯和行數(shù)據(jù)的添加功能過(guò)程中,如果有時(shí)間字段,應(yīng)該怎么讓時(shí)間字段可以有日歷和時(shí)間進(jìn)行選擇后輸入啊?  回復(fù)  更多評(píng)論
            
          # re: 如何使用ECSide列表組件構(gòu)建列表(內(nèi)附源碼)
          2009-11-25 15:22 | 小立飛刀
          @xx
          添加、編輯、刪除等功能我基本上沒有用到,但理論上來(lái)說(shuō),可以這樣處理:
          添加時(shí),需要定義一個(gè)區(qū)塊,如:
          <div id="add_template" style="display:none;">
          <input type="text" name="title">
          <input type="text" name="someDate" class="Wdate" onclick="WdatePicker({dateFmt:'yyyy-MM-dd', skin:'blue'})">
          ...
          </div>

          在里面定義一個(gè)選擇時(shí)間的input,我這里用的是My97DatePicker控件,就可以實(shí)現(xiàn)您說(shuō)的時(shí)間選擇了。  回復(fù)  更多評(píng)論
            
          # c ni ma ma
          2011-05-25 17:02 | dsf
          <2009年11月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          生存或毀滅,這是個(gè)必答之問(wèn)題:是否應(yīng)默默的忍受坎苛命運(yùn)之無(wú)情打擊,還是應(yīng)與深如大海之無(wú)涯苦難奮然為敵,并將其克服。此二抉擇,究竟是哪個(gè)較崇高?

          常用鏈接

          留言簿(12)

          隨筆分類(43)

          相冊(cè)

          收藏夾(7)

          朋友的博客

          電子資料

          搜索

          •  

          積分與排名

          • 積分 - 302772
          • 排名 - 192

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 阳原县| 汤阴县| 故城县| 舞阳县| 芮城县| 新乡市| 通山县| 广宁县| 建昌县| 万荣县| 吐鲁番市| 龙岩市| 芜湖市| 辽宁省| 宁陕县| 普安县| 全州县| 启东市| 长岭县| 四会市| 滦平县| 诸城市| 湾仔区| 淳安县| 长寿区| 农安县| 上虞市| 临澧县| 澄江县| 二手房| 清徐县| 龙井市| 伊春市| 武平县| 东平县| 齐河县| 济阳县| 新昌县| 佛学| 海口市| 浠水县|