java 列表组件_Jsp页面列表组件框架设计
一起學(xué)習(xí)
Jsp頁(yè)面列表組件框架設(shè)計(jì)
作者:李俊杰
概述
為了提高開(kāi)發(fā)效率,減少重復(fù)的頁(yè)面多次開(kāi)發(fā),提高系統(tǒng)的可配置性和代碼的可復(fù)用性,也是為了展示struts、hibernate框架,設(shè)計(jì)原則是降低顯示邏輯和數(shù)據(jù)的耦合,達(dá)到顯示邏輯和數(shù)據(jù)完全分離,即相同的數(shù)據(jù)使用不同的顯示邏輯,無(wú)須修改顯示邏輯,只需置換不同的顯示模版即可。
實(shí)現(xiàn)機(jī)制
其中SturtsAction是具體的需要調(diào)用列表的Action類,TempDataMap類是具體的列表數(shù)據(jù)的封裝類,TempData類是具體的表記錄類,即TempDataMap來(lái)適配TempData,把表記錄適配成我們需要的列表顯示類。
調(diào)用示例:
Action:
//獲取數(shù)據(jù)庫(kù)數(shù)據(jù)
listRowCount = query.findPayItemByParam(paramInfo,paramForm.getPageSize(),paramForm.getPageNo());
list = listRowCount.getList();
//調(diào)用列表組件
if(list != null && list.size() > 0)
ColDataMgrmgr = new ColDataMgr(getDataMaps(list));
//獲取列表的表列信息,數(shù)據(jù)信息
ArrayList colMetaInfos = mgr.getColMetaInfos();
ArrayList datas = mgr.getData();
//將列表信息傳到List頁(yè)面
request.setAttribute(CoreConstant.WEB_DISPLAY_COL_METAT_INFOS_KEY, colMetaInfos);
request.setAttribute(CoreConstant.WEB_DISPLAY_DATAS_KEY, datas);
同樣道理,給出的數(shù)據(jù)可以分發(fā)給打印組件和導(dǎo)出excel列表組件,根據(jù)列表的列信息和數(shù)據(jù)信息,導(dǎo)出excel和打印。
具體的map類的內(nèi)容可參照附件ReceiveItemAmountQueryMap.java文件。
獲取顯示列信息:
/**
*返回的list中每個(gè)元素是列元信息類對(duì)象,列元信息類對(duì)象包括列名稱,列顯示名稱,
*列顯示格式,其中列名稱是key
*導(dǎo)出excel和打印是同樣的道理
*/
public ArrayList getColMetaInfos()
{
ArrayList list = new ArrayList();
list.add(new ColMetaInfo("transCode", "單據(jù)編號(hào)", true, "height="20" align="center" nowrap"));
list.add(new ColMetaInfo("transDate", "單據(jù)日期", false, "height="20" align="center" nowrap"));
list.add(new ColMetaInfo("transTypeName", "業(yè)務(wù)類型", false, "height="20" align="left" nowrap"));
list.add(new ColMetaInfo("receiveOrgName", "收款單位", false, "height="20" align="left" nowrap"));
list.add(new ColMetaInfo("receiveAccountNo", "收款賬戶號(hào)", 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;
}
//適配數(shù)據(jù),根據(jù)數(shù)據(jù)的類型如日期型,裝換成需要的字符串形式,金額類數(shù)據(jù)也轉(zhuǎn)換成相//應(yīng)的字符串格式,保存到HashMap中。
public HashMap getColData()
{
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();
HashMap hm = new HashMap();
hm.put("transCode","?" IDataFormat.formatString(form.getTransCode()));
hm.put("transDate", "?" IDateFormat.toDateString(form.getTransDate()));
hm.put("transTypeName", "?" IDataFormat.formatString(form.getTransTypeName()));
hm.put("receiveOrgName", "?" IDataFormat.formatString(form.getReceiveOrgName()));
hm.put("receiveAccountNo", "?" IDataFormat.formatString(form.getReceiveAccountNo()));
hm.put("receiveBankName", "?" IDataFormat.formatString(form.getReceiveBankName()));
hm.put("extAccountNo", "?" IDataFormat.formatString(form.getTransApplyItem().getExtAccountNo()));
hm.put("extBankName", "?" IDataFormat.formatString(form.getTransApplyItem().getExtBankName()));
if (form.getTransApplyItem().getAmount() != null)
{
String sAmount = "?" IDataFormat.formatDisabledAmount(form.getTransApplyItem().getAmount().doubleValue() );
hm.put("amount", sAmount);
}
else
{
hm.put("amount", "0.00");
}
hm.put("memo", "?" IDataFormat.formatString(form.getTransApplyItem().getMemo()));
hm.put("SUPERLINK", link);
return hm;
}
附錄:
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();
}
抽象實(shí)現(xiàn)類DefaultDataMap
import java.util.ArrayList;
import java.util.HashMap;
/**
* @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;
}
}
ColDataMgr管理類:
import java.util.ArrayList;
import java.util.HashMap;
/**
* @author lijj
*
* To change the template for this generated type comment go to Window - Preferences - Java - Code Generation - Code and
* Comments
*/
public class ColDataMgr
{
ArrayListlist= null;
DataMapmap= null;
public ColDataMgr(ArrayList list)
{
this.list = list;
}
public ColDataMgr(DataMap map)
{
this.map = map;
}
public ArrayList getColMetaInfos()
{
if (list != null)
{
return ((DataMap) list.get(0)).getColMetaInfos();
}
else
{
return this.map.getColMetaInfos();
}
}
public ArrayList getExeclColMetaInfos()
{
if (list != null)
{
return ((DataMap) list.get(0)).getExeclColMetaInfos();
}
else
{
return this.map.getExeclColMetaInfos();
}
}
public ArrayList getPrintColMetaInfos()
{
if (list != null)
{
return ((DataMap) list.get(0)).getPrintColMetaInfos();
}
else
{
return this.map.getPrintColMetaInfos();
}
}
public ArrayList getData()
{
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;
}
public ArrayList getSearchInfos()
{
return getDataMap().getColSearchs();
}
public String getSearchUrl()
{
return getDataMap().getSearchUrl();
}
public HashMap getQueryData()
{
return getDataMap().getQueryData();
}
private DataMap getDataMap()
{
if (this.map != null)
{
return map;
}
else
{
return ((DataMap) list.get(0));
}
}
}
列元信息類ColMetaInfo
/**
* @author lijj
*
* To change the template for this generated type comment go to Window - Preferences - Java - Code Generation - Code and
* Comments
*/
public class ColMetaInfo
{
private Stringname;
private StringdisplayName;
private booleanisLink;
private String property;
public ColMetaInfo(String name, String displayName, boolean isLink, String property)
{
this.name = name;
this.displayName = displayName;
this.isLink = isLink;
this.property = property;
}
public String getDisplayName()
{
return displayName;
}
public void setDisplayName(String displayName)
{
this.displayName = displayName;
}
public boolean isLink()
{
return isLink;
}
public void setLink(boolean isLink)
{
this.isLink = isLink;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getProperty()
{
return property;
}
public void setProperty(String property)
{
this.property = property;
}
}
模版文件list.jsp
ArrayList colMetaInfos = (ArrayList) request.getAttribute("colMetaInfos");
ArrayList datas = (ArrayList) request.getAttribute("datas");
int colLen = colMetaInfos.size();
int resultCount = datas.size();
%>
ColMetaInfo colMeta = null;
for (int i = 0; i < colLen; i )
{
colMeta = (ColMetaInfo) colMetaInfos.get(i);
%>
}
%>
HashMap hm = null;
for (int i = 0; i < resultCount; i )
{
%>
hm = (HashMap) datas.get(i);
for (int j = 0; j < colLen; j )
{
colMeta = (ColMetaInfo) colMetaInfos.get(j);
%>
>
if (colMeta.isLink() && hm.get(colMeta.getName()) != null
&& !((String) hm.get(colMeta.getName())).equals(""))
{
%>
}
else
{
%>
}
%>
}
%>
}
%>
//沒(méi)有記錄顯示空白行
if (resultCount == 0)
{
%>
for (int i = 0; i < colLen; i )
{
colMeta = (ColMetaInfo) colMetaInfos.get(i);
%>
}
}
%>
Jsp使用列表模版的片斷
開(kāi)戶申請(qǐng)
新增" name="bt" class=button onClick="JavaScript:to_Add();">
總結(jié)
以上是生活随笔為你收集整理的java 列表组件_Jsp页面列表组件框架设计的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
 
                            
                        - 上一篇: java窗口绘图_JAVA-窗口中绘制图
- 下一篇: java文件怎么建立关联_如何创建两个J
