<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

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

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

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

    開發(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
    ?
    實現(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的過濾器,用于文件導(dǎo)出和語言編碼,忘記配置的話,會出現(xià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文件,寫這個文件的目的是:把公共的內(nèi)容集中在一個文件中,方便使用。一旦我們使用ecside 組件,哪個這些配置信息就可以直接引用。形式可以如下:
    ###########????????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
    首先來簡單介紹一下RSF(列表、排序、過濾)操作方式:
    ecside支持兩種RSF方式:?? 基于java collection層 和 基于數(shù)據(jù)庫層,下面分別介紹:

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

    ????
    public ?ActionForward?list(ActionMapping?mapping,?ActionForm?form,
    ????????????HttpServletRequest?request,?HttpServletResponse?response)?
    {
    ????????String?v_type?
    = ?request.getParameter( " type " );
    ????????
    // 0)?設(shè)定過濾條件
    ????????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)建時間倒序排列
    ????????
    // 1)?設(shè)定ECSide分頁對象
    ????????Limit?limit? = ?RequestUtils.getLimit(request);
    ????????
    // ?取總記錄數(shù)
    ???????? int ?pageNo? = ?RequestUtils.getPageNo(request);
    ????????
    int ?pagesize? = ?RequestUtils.getCurrentRowsDisplayed(request);
    ????????
    if ?(pagesize? == ? 0 )
    ????????????pagesize?
    = ?PAGESIZE;
    ????????
    // ?設(shè)置總記錄數(shù)及每頁記錄數(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)建了過濾條件及排序條件查詢數(shù)據(jù),通過queryForListByCriter方法,輸入當(dāng)前起始頁及每頁的顯示條數(shù)在數(shù)據(jù)層得到所需數(shù)據(jù)。詳見代碼中的注釋。另附數(shù)據(jù)處理層兩個方法的代碼:
    /*分頁查詢數(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();
    ????}


    /*計算數(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工具無關(guān),不管你使用什么方法只要能獲得一個集合就好,這里我用的是Hibernate獲得的集合。
    ?
    3)在JSP中使用ecside
    需要注意的是:
    1. items的值一定要和request.setAttribute(getEntityListName(), result); 屬性一致
    2. 可以引用屬性名做為值顯示,如:${bulletin.id}
    3. <ec:column property="name" title="公告名稱">property屬性值一定是映射文件中的某個屬性
    <% @?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" >
    <!-- ?校驗信息? -->
    ??
    < tr >
    ????
    < td? class ="left" > <% @?include?file = " /module/commons/htmlmessages.jsp " ? %> </ td > ????????????????
    ??
    </ tr >
    ??
    < tr >
    ????????
    < td? height ="30" >
    ????????????
    < span? style ="align:left;font-size:9pt;" >
    ????????????????請選擇公告
    ??????????????
    < 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 ="序號" ?width ="6%" >
    ????????????????????${GLOBALROWCOUNT}
    ????????????????
    </ ec:column >
    ????????????????
    < ec:column? property ="name" ?title ="公告名稱" >
    ????????????????????
    < a? href ="JavaScript:doStarting('${affair.id}')" ?title ="點擊查看" >< 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)建時間" ??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ù),請稍候');
    ??????????????????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ù),請稍候');
    ??????????????????????????window.location?
    = ?urlPrefix? + ?itemId;
    ????????????????????}

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

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

    ??????????????alert('請選擇一個公告!');
    ??????????}

    ???}

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

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

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

    ecside_list.jpg?


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


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

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

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

    解決方法是在action中封裝結(jié)果數(shù)據(jù)時處理一下導(dǎo)出的操作,取全部數(shù)據(jù),通過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ù)  更多評論
      
    # re: 如何使用ECSide列表組件構(gòu)建列表(內(nèi)附源碼)
    2009-03-09 10:43 | philip
    是否支持jstl標(biāo)簽  回復(fù)  更多評論
      
    # re: 如何使用ECSide列表組件構(gòu)建列表(內(nèi)附源碼)
    2009-03-09 15:41 | 小立飛刀
    @philip
    支持的 我給的例子中就用了 比如可以如下使用<fmt:formatDate>標(biāo)簽:

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

    但是好像不能作為屬性使用
      回復(fù)  更多評論
      
    # re: 如何使用ECSide列表組件構(gòu)建列表(內(nèi)附源碼)
    2009-11-01 15:21 | 剛學(xué)ecside
    import net.allen.core.struts.StrutsEntityAction;
    大哥,這個類沒有啊
    能不能弄全一點啊,不勝感激!
    我QQ:417186803  回復(fù)  更多評論
      
    # re: 如何使用ECSide列表組件構(gòu)建列表(內(nèi)附源碼)
    2009-11-03 10:04 | 小立飛刀
    @剛學(xué)ecside
    這個類并無特殊用途,如果您用的是struts1.2的話,完全可以繼承DispatchAction。  回復(fù)  更多評論
      
    # re: 如何使用ECSide列表組件構(gòu)建列表(內(nèi)附源碼)[未登錄]
    2009-11-19 11:25 | xx
    請問用ecside組件時,實現(xiàn)對列數(shù)據(jù)的編輯和行數(shù)據(jù)的添加功能過程中,如果有時間字段,應(yīng)該怎么讓時間字段可以有日歷和時間進(jìn)行選擇后輸入啊?  回復(fù)  更多評論
      
    # re: 如何使用ECSide列表組件構(gòu)建列表(內(nèi)附源碼)
    2009-11-25 15:22 | 小立飛刀
    @xx
    添加、編輯、刪除等功能我基本上沒有用到,但理論上來說,可以這樣處理:
    添加時,需要定義一個區(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>

    在里面定義一個選擇時間的input,我這里用的是My97DatePicker控件,就可以實現(xiàn)您說的時間選擇了。  回復(fù)  更多評論
      
    # c ni ma ma
    2011-05-25 17:02 | dsf
    <2009年1月>
    28293031123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

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

    常用鏈接

    留言簿(12)

    隨筆分類(43)

    相冊

    收藏夾(7)

    朋友的博客

    電子資料

    搜索

    •  

    積分與排名

    • 積分 - 302675
    • 排名 - 192

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: av大片在线无码免费| 今天免费中文字幕视频| 99无码人妻一区二区三区免费| 亚洲精品乱码久久久久久中文字幕| 韩国亚洲伊人久久综合影院| 国内一级一级毛片a免费| 久久亚洲国产成人影院| 成人毛片免费在线观看| 亚洲av无码久久忘忧草| www.黄色免费网站| 亚洲色大情网站www| 国产成人免费片在线观看| 老司机亚洲精品影院在线观看| 又粗又大又长又爽免费视频 | 中文字幕免费不卡二区| 久久亚洲国产精品一区二区| 免费成人高清在线视频| 亚洲最大的视频网站| 女人被弄到高潮的免费视频 | 国产伦精品一区二区免费| 亚洲日韩中文字幕在线播放| 日韩人妻一区二区三区免费| 亚洲成电影在线观看青青| 好爽…又高潮了免费毛片| 色网站在线免费观看| 亚洲精品午夜国产VA久久成人| 久久免费观看国产精品88av| 亚洲伊人久久大香线焦| 免费人成在线观看播放国产| a在线免费观看视频| 亚洲精品福利你懂| 亚洲精品线路一在线观看| 一区二区三区观看免费中文视频在线播放 | 亚洲 欧洲 自拍 另类 校园| 亚洲?V乱码久久精品蜜桃| 大地资源在线资源免费观看 | 久久久无码精品亚洲日韩软件| 久久青草免费91线频观看站街| 亚洲中文字幕无码中文| 伊人婷婷综合缴情亚洲五月| 中文毛片无遮挡高潮免费|