騎士の圣殿

           

          [轉(zhuǎn)]通用分頁(yè)標(biāo)簽【廢棄以前的兩個(gè)設(shè)計(jì)不合理的標(biāo)簽】

          對(duì)于以前我寫(xiě)的兩個(gè)分頁(yè)標(biāo)簽,現(xiàn)在存在很多設(shè)計(jì)不合理和實(shí)現(xiàn)的不好的地方。如果有使用的,建議大家廢棄掉
          如果給大家?guī)?lái)的誤導(dǎo),表示抱歉。

          希望這個(gè)能給大家一些啟發(fā),我信寫(xiě)得這個(gè)標(biāo)簽,在兩個(gè)項(xiàng)目中使用,還是蠻靈活和簡(jiǎn)單的。

          代碼及其jar下載:http://www.aygfsteel.com/Files/qixin000/PagerTag_src.rar
          導(dǎo)入其中的兩個(gè)jar即可,源代碼沒(méi)有common部分,但是已經(jīng)是所有的tag源碼了,僅作參考。

          使用方法:

          public class TopicPageData extends AbstractPagerData {
              private ITopicDao topicDao;

              private int categoryId = -1;
              private String keyword = null;
              private int auditId = EAuditStatus.All.getValue();

              public TopicPageData() {
                  topicDao = ApplicationContextFactory.getContentFacotry().getTopicDao();
              }

              public IPagerData getPagerData(PagerBean pagerBean) {
                  init(pagerBean);
                  return new IPagerData() {

                      public Object execute(PagerBean pagerBean) {
                          return topicDao.selectTopicByQuery(keyword, categoryId, EAuditStatus.valueOf(auditId), pagerBean.getFrom(), pagerBean.getPageSize());
                      }

                      public int getTotalCount(PagerBean pagerBean) {
                          return topicDao.selectTopicByQueryCount(keyword, categoryId, EAuditStatus.valueOf(auditId));
                      }
                  };
              }

              protected void init(PagerBean pagerBean) {
                  if (this.getParameterValue(pagerBean, "categoryId") != null)
                      categoryId = Integer.parseInt(this.getParameterValue(pagerBean, "categoryId").toString());
                  if (this.getParameterValue(pagerBean, "keyword") != null)
                      keyword = this.getParameterValue(pagerBean, "keyword").toString();
                  if (this.getParameterValue(pagerBean, "auditId") != null)
                      auditId = Integer.parseInt(this.getParameterValue(pagerBean, "auditId").toString());

              }
          }


          繼承抽象類(lèi)AbstractPagerData,實(shí)現(xiàn)其中的函數(shù)就行了
          init初始化從頁(yè)面得到的參數(shù)
          getPagerData獲得分頁(yè)后的數(shù)據(jù)函數(shù),它的返回值是一個(gè)接口,要用匿名內(nèi)部類(lèi)實(shí)現(xiàn)該接口
          IPagerData接口有兩個(gè)函數(shù)要實(shí)現(xiàn),一個(gè)是getTotalCount,返回?cái)?shù)據(jù)總數(shù)量,execute返回要顯示的一頁(yè)數(shù)據(jù)。
          然后頁(yè)面就能夠得到這些數(shù)據(jù)了

          頁(yè)面的使用方法:

          <%@ taglib prefix="pager" uri="http://www.yushunkeji.cn/taglib" %>
          <pager:pagerData id="topicListId" action="com.yushunkeji.cms.admin.topic.TopicPageData" pageSize="10"
                                   dataId="topicList"/>

                  <form id="topicListForm" action="cms_topicList.action" method="post">
                      <table>
                          <tr>
                              <td>
                                  關(guān)鍵字<input type="text" name="keyword" id="keyword" value="${param.keyword}"/>
                                  分類(lèi)<select name="categoryId" id="categoryId" onchange="topicListForm.submit();">
                                  <option value="-1">請(qǐng)選擇...</option>
                                  <c:forEach var="category" items="${categoryList}">
                                      <option value="${category.categoryId}" ${param.categoryId==category.categoryId?'selected':''}>${category.categoryTitle}</option>
                                  </c:forEach>
                              </select>
                                  審核
                                  <select name="auditId" id="auditId" onchange="topicListForm.submit();">
                                      <option value="-1">所有</option>
                                      <option value="0" ${param.auditId==0?"selected":""}>待審核</option>
                                      <option value="1" ${param.auditId==1?"selected":""}>已審核</option>
                                  </select>
                                  <input type="submit" id="query" value="查詢"/>
                                  <input type="submit" id="reset" value="重置"
                                         onclick="$('keyword').value='';$('categoryId').value=-1"/><br/>
                              </td>
                          </tr>
                      </table>
                      <table class="adminlist" cellspacing="1">
                          <thead>
                              <tr>
                                  <th width="2%" class="title"><input type="checkbox" onclick="checkAll(this,$('topicListForm'),'selectedId')">
                                  </th>
                                  <th width="5%" class="title">編號(hào)</th>
                                  <th class="title">標(biāo)題</th>
                                  <th width="8%" class="title">分類(lèi)</th>
                                  <th width="5%" class="title">作者</th>
                                  <th width="4%" class="title">審核</th>
                                  <th width="10%" class="title">操作</th>
                              </tr>
                          </thead>
                          <c:forEach var="topic" items="${topicList}">
                              <tr class="row0" onMouseOver="this.className='row1'" onMouseOut="this.className='row0'">
                                  <td><input type="checkbox" id="chkTopic" name="selectedId"
                                             value="${topic.topicId}"/></td>
                                  <td>${topic.topicId}</td>
                                  <td>
                                          <%--<a href="cms_topicTemplate.action?topic.topicId=${topic.topicId}"--%>
                                          <%--target=_blank>${topic.title}</a>--%>
                                      <c:choose>
                                          <c:when test="${topic.auditStatus==0}">
                                              <a href="${base}/cms/admin/cms_topicTemplate.action?topic.topicId=${topic.topicId}"
                                                 target=_blank>${topic.title}</a>
                                          </c:when>
                                          <c:when test="${topic.auditStatus==1}">
                                              <a href="${base}${topic.htmlFullPath}"
                                                 target=_blank>${topic.title}</a>
                                          </c:when>
                                      </c:choose>
                                  </td>
                                  <td>${topic.category.categoryTitle}</td>
                                  <td>${topic.author}</td>
                                  <td>${topic.auditStatus==1?'通過(guò)':'待審'}</td>
                                  <td>
                                      <c:if test="${ex:isAllowOperation(user,topic.topicId)}">
                                          <a href="#"
                                             onclick="document.popup.show('${base}/cms/admin/cms_referenceTopic.action?topic.topicId=${topic.topicId}', 660, 600, null);">相關(guān)</a>
                                          <a href="#"
                                             onclick="window.location.href='cms_topicInfo.action?action=edit&topic.topicId=${topic.topicId}'">編輯</a>
                                          <a href="#" onclick="deleteTopic(${topic.topicId})">刪除</a>
                                      </c:if>
                                      &nbsp;
                                  </td>
                              </tr>
                          </c:forEach>
                          <tfoot>
                              <td colspan="7">
                                  <div class="pagination">
                                      <pager:pager id="topicListId"/>
                                  </div>
                              </td>
                          </tfoot>
                      </table>

                  </form>

          注意其中的的pager標(biāo)簽的使用,有兩個(gè)一個(gè)是pager:pagerData,一個(gè)是pager:pager,兩個(gè)id要一直,dataid是頁(yè)面取數(shù)據(jù)的對(duì)象id,注意foreach循環(huán)topicList部分。

          posted on 2007-11-02 15:33 最後の騎士 閱讀(206) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): java技術(shù)

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(1)

          隨筆分類(lèi)

          隨筆檔案

          文章分類(lèi)

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 呼玛县| 化德县| 秦皇岛市| 沁水县| 海兴县| 武冈市| 闸北区| 兴海县| 会理县| 宜兰县| 葫芦岛市| 吉木萨尔县| 怀仁县| 深州市| 万年县| 阜康市| 墨玉县| 三河市| 喀什市| 甘肃省| 日喀则市| 凤山市| 广安市| 资阳市| 临沭县| 奉化市| 彩票| 米泉市| 通山县| 顺平县| 桃园县| 偃师市| 南和县| 岚皋县| 江都市| 乐陵市| 乐山市| 灵武市| 六枝特区| 文安县| 旅游|