Jsp页面列表组件框架设计

Jsp页面列表组件框架设计

                作者:李俊杰

概述

为了提高开发效率,减少重复的页面多次开发,提高系统的可配置性和代码的可复用性,也是为了展示strutshibernate框架,设计原则是降低显示逻辑和数据的耦合,达到显示逻辑和数据完全分离,即相同的数据使用不同的显示逻辑,无须修改显示逻辑,只需置换不同的显示模版即可。

实现机制

<v:shapetype o:spt="75" coordsize="21600,21600" filled="f" stroked="f" id="_x0000_t75" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t"><v:stroke joinstyle="miter"></v:stroke><v:formulas><v:f eqn="if lineDrawn pixelLineWidth 0"></v:f><v:f eqn="sum @0 1 0"></v:f><v:f eqn="sum 0 0 @1"></v:f><v:f eqn="prod @2 1 2"></v:f><v:f eqn="prod @3 21600 pixelWidth"></v:f><v:f eqn="prod @3 21600 pixelHeight"></v:f><v:f eqn="sum @0 0 1"></v:f><v:f eqn="prod @6 1 2"></v:f><v:f eqn="prod @7 21600 pixelWidth"></v:f><v:f eqn="sum @8 21600 0"></v:f><v:f eqn="prod @7 21600 pixelHeight"></v:f><v:f eqn="sum @10 21600 0"></v:f></v:formulas><v:path o:extrusionok="f" o:connecttype="rect" gradientshapeok="t"></v:path><o:lock v:ext="edit" aspectratio="t"></o:lock></v:shapetype><v:shape id="_x0000_i1025" type="#_x0000_t75" o:ole="" style="WIDTH: 411pt; HEIGHT: 419.25pt"><v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image001.emz" o:title=""></v:imagedata></v:shape>

其中Sturts  Action是具体的需要调用列表的Action类,TempDataMap类是具体的列表数据的封装类,TempData类是具体的表记录类,即TempDataMap来适配TempData,把表记录适配成我们需要的列表显示类。

调用示例:

Action

<o:p> </o:p>

//获取数据库数据

listRowCount  = query.findPayItemByParam(paramInfo,paramForm.getPageSize(),paramForm.getPageNo());

                     list = listRowCount.getList();

//调用列表组件

if(list != null && list.size() > 0)

ColDataMgr    mgr = new ColDataMgr(getDataMaps(list));

//获取列表的表列信息,数据信息

ArrayList colMetaInfos = mgr.getColMetaInfos();

ArrayList datas = mgr.getData();

// 将列表信息传到List页面

                     request.setAttribute(CoreConstant.WEB_DISPLAY_COL_METAT_INFOS_KEY, colMetaInfos);

                     request.setAttribute(CoreConstant.WEB_DISPLAY_DATAS_KEY, datas);

<o:p> </o:p>

同样道理,给出的数据可以分发给打印组件和导出excel列表组件,根据列表的列信息和数据信息,导出excel和打印。

<o:p> </o:p>

具体的map类的内容可参照附件ReceiveItemAmountQueryMap.java文件。

获取显示列信息:

/**

  *返回的list中每个元素是列元信息类对象,列元信息类对象包括列名称,列显示名称,

  *列显示格式,其中列名称是key

  * 导出excel和打印是同样的道理

  */

public ArrayList getColMetaInfos()

       {

<o:p> </o:p>

              ArrayList list = new ArrayList();

              list.add(new ColMetaInfo("transCode", " 单据编号 ", true, "height=\"20\" align=\"center\" nowrap"));

              list.add(new ColMetaInfo("transDate", " 单据日期 ", false, "height=\"20\" align=\"center\" nowrap"));

              list.add(new ColMetaInfo("transTypeName", " 业务类型 ", false, "height=\"20\" align=\"left\" nowrap"));

              list.add(new ColMetaInfo("receiveOrgName", " 收款单位 ", false, "height=\"20\" align=\"left\" nowrap"));

              list.add(new ColMetaInfo("receiveAccountNo", " 收款账户号 ", false, "height=\"20\" align=\"center\" nowrap"));

              list.add(new ColMetaInfo("receiveBankName", " 收款银行 ", false, "height=\"20\" align=\"left\" nowrap"));

              list.add(new ColMetaInfo("extAccountNo", " 付款账户 ", false, "height=\"20\" align=\"center\" nowrap"));

              list.add(new ColMetaInfo("extBankName", " 付款银行 ", false, "height=\"20\" align=\"left\" nowrap"));

              list.add(new ColMetaInfo("amount", "     ", false, "height=\"20\" align=\"right\" nowrap"));

              list.add(new ColMetaInfo("memo", "     ", false, "height=\"20\" align=\"left\" nowrap"));

             

              return list;

       }

//适配数据,根据数据的类型如日期型,装换成需要的字符串形式,金额类数据也转换成相//应的字符串格式,保存到HashMap中。

public HashMap getColData()

       {

<o:p> </o:p>

               StringBuffer sb = new StringBuffer("receiveItemAmountQueryAction.do?operation=");

               sb.append(CoreConstant.WEB_OPERATION_TYPE_TO_UPDATE_KEY);

               sb.append("&id=");

               sb.append(String.valueOf(form.getTransApplyItem().getTransApplyID().longValue()));

               String link = sb.toString();

<o:p> </o:p>

              HashMap hm = new HashMap();

              hm.put("transCode","&nbsp;"+IDataFormat.formatString(form.getTransCode()));

              hm.put("transDate", "&nbsp;"+IDateFormat.toDateString(form.getTransDate()));

              hm.put("transTypeName", "&nbsp;"+IDataFormat.formatString(form.getTransTypeName()));

              hm.put("receiveOrgName", "&nbsp;"+IDataFormat.formatString(form.getReceiveOrgName()));

              hm.put("receiveAccountNo", "&nbsp;"+IDataFormat.formatString(form.getReceiveAccountNo()));

              hm.put("receiveBankName", "&nbsp;"+IDataFormat.formatString(form.getReceiveBankName()));

              hm.put("extAccountNo", "&nbsp;"+IDataFormat.formatString(form.getTransApplyItem().getExtAccountNo()));

              hm.put("extBankName", "&nbsp;"+IDataFormat.formatString(form.getTransApplyItem().getExtBankName()));

             

              if (form.getTransApplyItem().getAmount() != null)

              {

                     String sAmount = "&nbsp;"+IDataFormat.formatDisabledAmount(form.getTransApplyItem().getAmount().doubleValue() );

                     hm.put("amount", sAmount);

              }

              else

              {

                     hm.put("amount", "0.00");

              }

             

              hm.put("memo", "&nbsp;"+IDataFormat.formatString(form.getTransApplyItem().getMemo()));

               hm.put("SUPERLINK", link);

<o:p> </o:p>

              return hm;

       }

附录:

<o:p> </o:p>

DataMap接口:

/**

 * @author lijj

 *

 * To change the template for this generated type comment go to

 * Window - Preferences - Java - Code Generation - Code and Comments

 */

public interface DataMap {

       public ArrayList getColMetaInfos();

       public ArrayList getExeclColMetaInfos();

       public ArrayList getPrintColMetaInfos();

       public ArrayList getColSearchs();

       public HashMap getQueryData();

       public String getSearchUrl();

       public HashMap getColData();

}

<o:p> </o:p>

抽象实现类DefaultDataMap

import java.util.ArrayList;

import java.util.HashMap;

<o:p> </o:p>

<o:p> </o:p>

<o:p> </o:p>

/**

 * @author lijj

 *

 * To change the template for this generated type comment go to

 * Window - Preferences - Java - Code Generation - Code and Comments

 */

public abstract class DefaultDataMap implements DataMap{

       public abstract ArrayList getColMetaInfos();      

       public abstract HashMap getColData();

       public ArrayList getExeclColMetaInfos()

       {

              return new ArrayList();

       }

       public ArrayList getPrintColMetaInfos()

       {

              return new ArrayList();

       }

       public String getSearchUrl()

       {

              return null;

       }

       public HashMap getQueryData()

       {

              return null;

       }

       public ArrayList getColSearchs()

       {

              ArrayList retList = new ArrayList();

              return retList;

       }

      

}

<o:p> </o:p>

ColDataMgr管理类:

import java.util.ArrayList;

import java.util.HashMap;

<o:p> </o:p>

/**

 * @author lijj

 *

 * To change the template for this generated type comment go to Window - Preferences - Java - Code Generation - Code and

 * Comments

 */

public class ColDataMgr

{

<o:p> </o:p>

       ArrayList list   = null;

<o:p> </o:p>

       DataMap        map        = null;

<o:p> </o:p>

       public ColDataMgr(ArrayList list)

       {

<o:p> </o:p>

              this.list = list;

       }

<o:p> </o:p>

       public ColDataMgr(DataMap map)

       {

<o:p> </o:p>

              this.map = map;

       }

<o:p> </o:p>

       public ArrayList getColMetaInfos()

       {

<o:p> </o:p>

              if (list != null)

              {

                     return ((DataMap) list.get(0)).getColMetaInfos();

              }

              else

              {

                     return this.map.getColMetaInfos();

              }

       }

<o:p> </o:p>

       public ArrayList getExeclColMetaInfos()

       {

<o:p> </o:p>

              if (list != null)

              {

                     return ((DataMap) list.get(0)).getExeclColMetaInfos();

              }

              else

              {

                     return this.map.getExeclColMetaInfos();

              }

       }

<o:p> </o:p>

       public ArrayList getPrintColMetaInfos()

       {

<o:p> </o:p>

              if (list != null)

              {

                     return ((DataMap) list.get(0)).getPrintColMetaInfos();

              }

              else

              {

                     return this.map.getPrintColMetaInfos();

              }

       }

<o:p> </o:p>

       public ArrayList getData()

       {

<o:p> </o:p>

              ArrayList retList = new ArrayList();

              DataMap dataMap = null;

              if (list != null)

              {

                     for (int i = 0; i < list.size(); i++)

                     {

                            dataMap = (DataMap) list.get(i);

                            retList.add(dataMap.getColData());

                     }

              }

              return retList;

       }

<o:p> </o:p>

       public ArrayList getSearchInfos()

       {

<o:p> </o:p>

              return getDataMap().getColSearchs();

       }

<o:p> </o:p>

       public String getSearchUrl()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值