ITeye博客

集成valueList配置详解及动态加载XML源码扩展

mengqingyu · 2010-06-21 16:28 · JavaWeb · 编程语言 · C · C++ · XML · JSP · Web · Markdown

集成valueList配置方法: 1.在[url]http://valuelist.sourceforge.net/index.html[/url]官方网站下载最新版valueList war包,其中包含了jar包和实例等所有相关内容。 2.valueList.jar,valuelist.tld拷贝到WEB-INF下(该文件也是从ValueList.war中解压出来的)。 3.创建一个applicationContext-valueList.xml文件,并且添加valuelist的entry。 [code="xml"] xml内容如下: false true 10 desc name 2 select id from test [/code]4.在action类里封装如下方法(valueListHelper需要注入): [code="java"] /** * @function:默认查询,查询结果放到request的list变量中 * @param adapter根据adapter变量内容在xml中寻找对应标签如上例中testAdapter * @param queries参数内容如需要传入查询条件放入map中 * @param tableId根据tableId变量内容在jsp页面中寻找对应root标签的id * @param request查询结果存入request中 */ public void setValueListToRequest(String adapter, Map queries, String tableId, HttpServletRequest request) { Map map = ValueListRequestUtil.getRequestParameterMap(request, tableId); map.putAll(queries); ValueListInfo info = new ValueListInfo(map); if (map.get("limit")!=null) { info.setPagingNumberPer(Integer.parseInt(map.get("limit").toString()));//每页记录数 } else { info.setPagingNumberPer(Integer.MAX_VALUE - 1); // 不分页时取integer最大值(原来是默认80会有数据不全问题) } if (map.get("start")!=null) { info.setPagingPage(Integer.parseInt(map.get("start").toString()) / info.getPagingNumberPer() + 1);//页数 } else { info.setPagingPage(1); // 不分页时默认按照从第1页开始 } ValueList valueList = valueListHelper.getValueList(adapter, info); valueListHelper.backupInfoFor(request, info, tableId); valueListHelper.setValueListTo(request, valueList, "list");//list为结果集的键 } /** * * @function:获得表中数据 * @param adapter key值 * @param params 需要传的参数 * @return ValueList对象 * @author: mengqingyu 2011-10-18 下午05:11:34 */ public ValueList getValueList(String adapter, Map params) { ValueListInfo info = new ValueListInfo(params); if (params.get("limit")!=null) { info.setPagingNumberPer(Integer.parseInt(params.get("limit").toString()));//每页记录数 } else { info.setPagingNumberPer(Integer.MAX_VALUE - 1); // 不分页时取integer最大值(原来是默认80会有数据不全问题) } if (params.get("start")!=null) { info.setPagingPage(Integer.parseInt(params.get("start").toString()) / info.getPagingNumberPer() + 1);//页数 } else { info.setPagingPage(1); // 不分页时默认按照从第1页开始 } ValueList valueList = valueListHelper.getValueList(adapter, info); return valueList; } /** * * @function:将valueList对象转换成ArrayList对象 * @param adapter * @param params * @return * @author: mengqingyu 2011-10-18 下午05:12:31 */ public List getValuelistToListMap(String adapter, Map params) { ValueList valueList = this.getValueList(adapter, params); List listBean = valueList.getList(); List listMap = new ArrayList(); for(BasicDynaBean dynaBean : listBean){ Map map = new HashMap(); DynaProperty[] dynaProperties = dynaBean.getDynaClass().getDynaProperties(); for (int i = 0; i < dynaProperties.length; i++) { String key = dynaProperties[i].getName(); Object o = dynaBean.get(key); if(o!=null){ map.put(key, o.toString()); } } listMap.add(map); } return listMap; }[/code]5.jsp页面代码: [code="html"]需要引入标签 <%@ taglib uri="/WEB-INF/tld/valuelist.tld" prefix="vlh"%> <%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> valueList查询代码list为结果集的键,如果不想用vlh标签,需要在后台对list结果集重新封装来实现。 提交表单需要隐藏当前分页属性 [/code]6.加入valueList分页按钮图片 microsoftLook.properties拷贝到源码目录下(该文件也是从ValueList.war中解压出来的)。 [code="xml"]在xml中加入如下配置: classpath:microsoftLook.properties microsoftLook UTF-8 microsoftLook images/valueList false false true [/code]7.修改valueList配置文件内容无需重启服务的方法: [code="java"]需要自定义两个类文件取代valueList.jar中的类文件。 DefaultValueListHandlerImpl.java和Configuration.java DefaultValueListHandlerImpl中改写引用Configuration是自定义类而不是jar中的类。 Configuration中加入: /** * * @function: DEBUG模式 * @return */ public Map getAdapters() { return this.adapters; } 原类中无此方法。 接下来在访问的超类中加入如下内容: protected static Boolean isDebug = false; //valueList调试模式 /** * @function:读取valueList配置文件 */ private void reloadValueListContext() { if(isDebug){ try { DefaultValueListHandlerImpl handler = (DefaultValueListHandlerImpl) valueListHelper.getValueListHandler(); String path = new File(this.getClass().getResource("/").getPath()).getParent(); FileSystemXmlApplicationContext fileSystemXmlApplicationContext = new FileSystemXmlApplicationContext(new String[]{ path + "/springContext/applicationContext-page*.xml", path + "/springContext/applicationContext-datasource*.xml"}); DefaultValueListHandlerImpl handlerDebug = (DefaultValueListHandlerImpl)fileSystemXmlApplicationContext.getBean("valueListHelper"); Map resultAdapters = handler.getConfig().getAdapters(); resultAdapters.putAll(handlerDebug.getConfig().getAdapters()); handler.getConfig().setAdapters(resultAdapters); } catch (Exception e) { e.printStackTrace(); } } } 在自定义的setValueListToRequest方法中加入reloadValueListContext方法。 idDebug变量内容可以通过前台页面传入来赋值。[/code]

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。