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

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

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

    posts - 78, comments - 34, trackbacks - 0, articles - 1
      BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

    今日的北京氣溫回升,昨天是降溫。天氣的變暖,讓大家感覺十分溫暖,課上睡意連綿。湯兄弟有發(fā)現(xiàn)大家的狀況,所以今天拿出了一點(diǎn)時(shí)間與大家交流學(xué)習(xí)方法或技術(shù)上的一些問題。授課進(jìn)度完全在掌握之中。

    未來三天的內(nèi)容,學(xué)習(xí)使用JBMP解決審批流轉(zhuǎn)這一大模塊的需求。今日的課程內(nèi)容比較簡(jiǎn)單,但在實(shí)際項(xiàng)目中的應(yīng)用卻十分重要。把WEB基礎(chǔ)搞的差不多了,這些框架并沒什么難的。更多的是應(yīng)該多使用,多熟悉他們。兩大重點(diǎn)內(nèi)容:通用超強(qiáng)分頁功能、JBPM審批流程管理。

    一、通用超強(qiáng)分頁功能

    1.分頁效果

    wps_clip_image-26256

    (圖1.1

    1.1中顯示的分頁功能是目前我見到的,功用最全的分頁功能。當(dāng)然也是論壇中比較常用的分頁功能。我們今日就實(shí)現(xiàn)這個(gè)通用超級(jí)分頁功能。

    2.分頁Bean

    湯老師使用自己的講課風(fēng)格(應(yīng)該也是他做項(xiàng)目時(shí)的編寫風(fēng)格),由廣入微、由粗糙到細(xì)致。使用他的方法做分析比較好,這或許是通用的分析方式吧!

    我們看圖1.1中具有的屬性:

    v 頁碼:1/11

    v 每頁顯示:30

    v 總記錄數(shù):301

    v 分頁: [首頁] [上一頁] [下一頁] [尾頁] 1 2 3 4 5 6 7 8 9 10

    OK,我們根據(jù)頁面信息取出了分頁Bean的屬性,并設(shè)計(jì)分頁Bean

    import java.util.List;

    public class PageView {

    // 通過參數(shù)指定的信息

    private int currentPage;// 當(dāng)前頁碼

    private int pageSzie;// 每頁顯示記錄數(shù)量

    // 通過查詢數(shù)據(jù)庫獲取的信息,外部獲取

    private int recordTotal;// 總記錄數(shù)

    private List recordList;// 當(dāng)前面記錄信息列表

    // 通過計(jì)算生成的信息

    private int pageTotal;// 總頁面數(shù)量

    private int startIndex;// 起始頁面索引

    private int endIndex;// 結(jié)束頁面索引

    // 顯示的頁面數(shù)量

    private static final int PAGE_INDEX_COUNT = 10;

    // 在構(gòu)造方法中生成各種需要的信息

    public PageView(int currentPage, int pageSize, int recordTotal,

    List recordList) {

    this.currentPage = currentPage;

    this.pageSzie = pageSize;

    this.recordTotal = recordTotal;

    this.recordList = recordList;

    // 通過計(jì)算生成startIndex和endIndex

    /*

    * 因?yàn)轱@示的頁面索引數(shù)量是有限的 我們不能把所以的頁面索引一下子全列出來 我們需要?jiǎng)討B(tài)顯示頁面索引列表

    */

    this.pageTotal = (this.recordTotal + this.pageSzie - 1) / this.pageSzie;

    // 如果頁面總數(shù)<=顯示頁面索引數(shù)量

    if (this.pageTotal <= PAGE_INDEX_COUNT) {

    this.startIndex = 1;

    this.endIndex = this.pageTotal;

    } else {

    // 根據(jù)當(dāng)前頁面索引生成,頁面起始索引和結(jié)束索引。

    // 區(qū)分偶數(shù)和奇數(shù) 頁面索引數(shù)量

    if (PAGE_INDEX_COUNT % 2 == 0) {

    this.startIndex = this.currentPage - (PAGE_INDEX_COUNT / 2 - 1);

    this.endIndex = this.currentPage + (PAGE_INDEX_COUNT / 2);

    } else {

    this.startIndex = this.currentPage - (PAGE_INDEX_COUNT / 2);

    this.endIndex = this.currentPage + (PAGE_INDEX_COUNT / 2);

    }

    // 如果生成的起始索引小于1

    if(this.startIndex < 1){

    this.startIndex = 1;

    this.endIndex = PAGE_INDEX_COUNT;

    }

    // 如果生成的結(jié)束索引大于總頁面索引數(shù)量

    if(this.endIndex > this.pageTotal){

    this.endIndex = this.pageTotal;

    this.startIndex = this.pageTotal - PAGE_INDEX_COUNT;

    }

    }

    }

    // ...getters AND setters

    }

    3.審批流程的DispathcAction

    我們與上次課程一樣,需要為審批流程編寫一個(gè)DispatchAction。涉及到顯示審批流程列表只有一個(gè)方法——list

    /** 

     * 顯示審批流程列表 

     */

    public ActionForward list(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)

    throws Exception {

    int pageNum = Integer.parseInt(request.getParameter("pageNum"));

    // 調(diào)用ProcessDefinitionService接口的getPageView方法獲取PageView對(duì)象

    PageView pageView = processDefinitionService.getPageView(pageNum);

    // 將PageView對(duì)象存放到request的pageView屬性中

    request.setAttribute("pageView", pageView);

    return mapping.findForward("list"); // list.jsp

    }

    其中用到的“processDefinitionService.getPageView”方法:

    /**

     * 獲取pageView信息

     */

    public PageView getPageView(int pageNum) {

    // 每面顯示10條記錄

    int pageSize = 10;

    // 查詢數(shù)據(jù)庫

    // 使用Number防止不同數(shù)據(jù)庫返回的數(shù)值類型不同,而引發(fā)的異常。

    int count = ((Number) this.getSession().createQuery(

    "SELECT COUNT(*) FROM " + ProcessDefinition.class.getName()

    + " pd").uniqueResult()).intValue();

    // 第一條記錄的索引

    int firstRecoderIndex = (pageNum - 1) * pageSize;

    // 獲取記錄列表

    List list = this.getSession().createQuery(

    "FROM " + ProcessDefinition.class.getName() + " pd")

    .setFirstResult(firstRecoderIndex).setMaxResults(pageSize)

    .list();

    return new PageView(pageNum, pageSize, count, list);

    }

    4.顯示分頁信息的pageView.jspf頁面

    多處使用到分頁頁面,所以我們將分頁頁面單獨(dú)提取出來。如果有哪個(gè)頁面需要顯示分頁信息,直接include就可以了。

    <%@ page language="java" pageEncoding="utf-8" %>

    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

    <c:if test="${pageView.totalPage gt 1 }">

    <!-- 分頁信息 -->

    頁碼:${pageView.currentPage}/${pageView.totalPage}頁

    每頁顯示:${pageView.pageSize}條

    總記錄數(shù):${pageView.recordCount}條

    分頁:

    <a href="javascript:gotoPage(1)">[首頁]</a> 

    <c:if test="${pageView.currentPage gt 1}">

    <a href="javascript:gotoPage(${pageView.currentPage - 1})">[上一頁]</a> 

    </c:if>

    <c:if test="${pageView.currentPage lt pageView.totalPage}">

    <a href="javascript:gotoPage(${pageView.currentPage + 1})">[下一頁]</a> 

    </c:if>

    <a href="javascript:gotoPage(${pageView.totalPage})">[尾頁]</a>

    <!-- 顯示頁碼 -->

    <c:forEach begin="${pageView.startPageIndex}" end="${pageView.endPageIndex}" var="pageNum">

    <c:if test="${pageNum eq pageView.currentPage}">

    <span class="current_page">${pageNum}</span>

    </c:if>

    <c:if test="${pageNum ne pageView.currentPage}">

    <a href="javascript:gotoPage(${pageNum})">${pageNum}</a>

    </c:if>

    </c:forEach>

    轉(zhuǎn)到:

    <input type="text" id="txtPageNum" size="4" class="input_pagenum"/>

    <input type="button" onclick="gotoPage(document.getElementById('txtPageNum').value)" value="Go"/>

    <script type="text/javascript">

    /**

    * 跳轉(zhuǎn)到指定的頁碼

    */

    function gotoPage( pageNum ){

    if( isNaN(pageNum) ){ // not a number

    alert("請(qǐng)輸入正確的頁碼");

    document.getElementById('txtPageNum').focus();

    return false;

    }

    if( pageNum < 1 || pageNum > ${pageView.totalPage} ){

    alert("請(qǐng)輸入正確的頁碼,范圍為 1-${pageView.totalPage}");

    document.getElementById('txtPageNum').focus();

    return false;

    }

    window.location.href = getPageViewUrl( pageNum );

    // getPageViewUrl為在include頁面添加的javscript代碼

         // 所以此頁面可以適用于任何分頁信息的顯示例如下:

    //function getPageViewUrl( pageNum ){

    // return "?method=list&pageNum=" + pageNum;

    //}

    }

    </script>

    </c:if>

    二、審批流轉(zhuǎn)管理

    審批流轉(zhuǎn)就是把單位內(nèi)部的各項(xiàng)審批電子化,如工作請(qǐng)求、出差申請(qǐng)、采購申請(qǐng)、請(qǐng)假、報(bào)銷等日常工作流程。

    審批流轉(zhuǎn)(工作流):

    1.流程與表單管理

    2.執(zhí)行流程

    3.查詢

    有類似的審批請(qǐng)求,有兩大重點(diǎn):流程定義和表單模板,一個(gè)表單對(duì)應(yīng)一個(gè)流程。

    要求:

    1.方便 定義/修改 與 管理 流程定義

    2.方便 定義/修改 與 管理 表單模板

    3.執(zhí)行流程(讓表單(數(shù)據(jù))按指定的流程進(jìn)行流轉(zhuǎn),并且記錄)

    4.方便查詢所有的表單實(shí)例(數(shù)據(jù)) 記錄(查詢流轉(zhuǎn)過的表單)

    今日沒有講解設(shè)計(jì)與審批流轉(zhuǎn)相關(guān)的模塊,只是講解將打包成zipJBPM工作流自動(dòng)部署到OA項(xiàng)目中,并可查看顯示工作流的文件信息以及刪除工作流。

    1.顯示部署流程

    /** 

     * 部署流程頁面 

     */

    public ActionForward deployUI(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)

    throws Exception {

    return mapping.findForward("deployUI"); // deployUI.jsp

    }

    2.部署流程

    /** 

     * 部署流程 

     */

    public ActionForward deploy(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)

    throws Exception {

    try {

    // 獲取<html:file>表單提交過來的流程資源

    ProcessDefinitionActionForm adaf = (ProcessDefinitionActionForm) form;

    ZipInputStream zipIn = new ZipInputStream(adaf.getParResource().getInputStream());

    // 創(chuàng)建流程定義

    ProcessDefinition pd = ProcessDefinition.parseParZipInputStream(zipIn);

    // 部署流程定義

    this.processDefinitionService.deploy(pd);

    } catch (Exception e) {

    // 發(fā)生異常顯示錯(cuò)誤

    ActionErrors errors = new ActionErrors();

    errors.add("error", new ActionMessage("非法的文件格式!",false));

    this.saveErrors(request, errors);

    return mapping.findForward("deployUI");

    }

    return mapping.findForward("toList"); // path="/pd.do?method=list" redirect="true"

    }

    因?yàn)椴渴鹆鞒虝r(shí)確保一個(gè)線程使用的是同一個(gè)“JbpmContext”,并確保Jbpm事件的正確提交或回滾。所以我們還需要為JbpmContext添加一個(gè)過濾器。

    3.刪除流程

    /**

     * 刪除流程

     */

    public ActionForward del(ActionMapping mapping, ActionForm form,

    HttpServletRequest request, HttpServletResponse response)

    throws Exception {

    // 獲取流程ID并刪除

    Long id = Long.parseLong(request.getParameter("id"));

    this.processDefinitionService.delete(id);

    // 需要刷新流程顯示列表

    String pageNum = request.getParameter("pageNum");

    ActionForward af = mapping.findForward("toList");

    return new ActionForward(af.getPath() + "&pageNum=" + pageNum, af.getRedirect());

    }

    4.查看流程中的“processdefinition.xml”文件

    /**

     * 查詢流程定義文件(processdefinition.xml

     */

    public ActionForward showProcessFile(ActionMapping mapping,

    ActionForm form, HttpServletRequest request,

    HttpServletResponse response) throws Exception {

    // 獲取流程id

    Long id = Long.parseLong(request.getParameter("id"));

    // 獲取流程定義

    ProcessDefinition pd = this.processDefinitionService.getById(id);

    // 獲取文件

    byte[] content = pd.getFileDefinition().getBytes(

    "processdefinition.xml");

    // 寫出文件

    response.setContentType("text/xml;charset=UTF-8");

    response.getWriter().write(new String(content, "UTF-8"));

    return null;

    }

    5.查看流程中的“processimage.jpg”文件

    /**

     * 查詢流程圖片(processimage.jpg

     */

    public ActionForward showProcessImage(ActionMapping mapping,

    ActionForm form, HttpServletRequest request,

    HttpServletResponse response) throws Exception {

    // 獲取流程id

    Long id = Long.parseLong(request.getParameter("id"));

    // 獲取流程定義

    ProcessDefinition pd = this.processDefinitionService.getById(id);

    // 獲取文件

    byte[] content = pd.getFileDefinition().getBytes("processimage.jpg");

    // 寫出文件

    response.setContentType("image/jpeg");

    response.getOutputStream().write(content);

    return null;

    }

    明天將學(xué)習(xí)自定義表單模板,和向流程中加入控制代碼。今天的內(nèi)容還需要在大腦里整理整理...

    加油!


    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 黄色免费在线网址| 18女人毛片水真多免费| 亚洲精品无码久久千人斩| 日韩精品内射视频免费观看| 久久精品国产亚洲AV蜜臀色欲| 日本二区免费一片黄2019| 国产美女视频免费观看的网站| 亚洲美女人黄网成人女| 国产午夜鲁丝片AV无码免费| 日本中文字幕免费高清视频| 亚洲AV日韩综合一区尤物| 伊人久久大香线蕉亚洲五月天| 四虎精品视频在线永久免费观看| 国产亚洲视频在线| 亚洲精品高清国产麻豆专区| 又黄又爽无遮挡免费视频| 精品无码国产污污污免费网站| 性色av极品无码专区亚洲| 亚洲国产精品久久久久网站| 免费v片在线观看品善网| 最近中文字幕国语免费完整| 一级特黄录像视频免费| 国产亚洲玖玖玖在线观看| 亚洲美女又黄又爽在线观看| 免费无码黄网站在线观看| 99热在线观看免费| 精精国产www视频在线观看免费| 亚洲综合精品伊人久久| 久久亚洲私人国产精品| 国产成人麻豆亚洲综合无码精品| 久久久久国色AV免费观看性色| 国产一区二区免费视频| 免费无码一区二区| 亚洲av无码专区在线观看亚| 亚洲激情校园春色| 亚洲国产天堂在线观看| 国产亚洲欧洲Aⅴ综合一区 | 最近中文字幕免费2019| 中文永久免费观看网站| 免费的黄网站男人的天堂| 亚洲精品久久无码|