displaytag TableProperties扩展

早就在项目中使用了displaytag1.1作为列表展现的页面组件。displaytag相对于ext不同,是服务器端的ui组件, 能很好的支持分页和排序,也能通过扩展行列装潢器来自定义行和列,通过更换css方便替表格风格。在一般项目中都很合适, 所以我从第一个项目开始就一直用到了现在。
一直以来有一个地方总觉得别扭, 就是displaytag.properties这个配置文件, 首先它是支持国际化的,于是就会有displaytag_xx.properties。但还有一个builtin的,就是displaytag.properties,存在于org/displaytag/properties/下,跟TableProperties.class在一起。
看看这些版本的displaytag.properties是如何加载的,打开TableProperties看看:

private TableProperties(Locale myLocale) throws TablePropertiesLoadException
{
this.locale = myLocale;
// default properties will not change unless this class is reloaded
Properties defaultProperties = loadBuiltInProperties();//这里是只能加载TableProperties.class同路径下的displaytag.properties

properties = new Properties(defaultProperties);
addProperties(myLocale);

// Now copy in the user properties (properties file set by calling setUserProperties()).
// note setUserProperties() MUST BE CALLED before the first TableProperties instantation
Enumeration keys = userProperties.keys();
while (keys.hasMoreElements())
{
String key = (String) keys.nextElement();
if (key != null)
{
properties.setProperty(key, (String) userProperties.get(key));
}
}
}

可以看出,是先加载displaytag.properties,再根据locale记载国际化版本的。
好了,既然如此,为了合理分配这些文件的职责。我想做一个调整,就是让displaytag.properties保存公用的核心配置,比如:
pagination.sort.param=sort
pagination.sortdirection.param=dir
pagination.pagenumber.param=page
pagination.searchid.param=searchid
pagination.sort.asc.value=asc
pagination.sort.desc.value=desc
pagination.sort.skippagenumber=true
为了能自己配置displaytag.properties,我将org/displaytag/properties/中的该文件删除了,然后再classpath的根目录下添加了一个displaytag.properties,并填入配置信息。

国际化版本的displaytag_xx.properties就只保存那些语言相关的信息,比如
basic.msg.empty_list=没有记录被找到

如此对displaytag.properties做了修改之后, 会发现有一个错误,说displaytag.properties找不到了。
看看TableProperties.loadBuiltInProperties():

private static Properties loadBuiltInProperties() throws TablePropertiesLoadException
{
Properties defaultProperties = new Properties();

try
{
InputStream is = TableProperties.class..getResourceAsStream(DEFAULT_FILENAME); //查找TableProperties.class相同路径之下的displaytag.properties

if (is == null)
{
throw new TablePropertiesLoadException(TableProperties.class, DEFAULT_FILENAME, null);
}
defaultProperties.load(is);
}
catch (IOException e)
{
throw new TablePropertiesLoadException(TableProperties.class, DEFAULT_FILENAME, e);
}

return defaultProperties;
}

因为TableProperties.class所在目录下的displaytag.properties已经被删除了, 所以要更改这里的获取方法,改成:
InputStream is = TableProperties.class.getClassLoader().getResourceAsStream(DEFAULT_FILENAME);
这样能找到整个classloader体系之下的classpath中的resource

这样就能正常看到分页了, 不过displaytag.properties的中文显示为乱码。继续修改TableProperties:

private String getProperty(String key)
{
String val = this.properties.getProperty(key);
if (val != null){
try {
val = new String(val.getBytes("ISO8859-1"), "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("UnsupportedEncodingException occured");
}
}

return val;
}

经过如此改造,且让displaytag.properties各类版本文件都保持utf-8编码, 就能够看到正确中文了。

其实displaytag不爽的地方不止以上几个, 还有一个一直想改, 有空想下能否实现。就是当外部分页时,也就是采取动态分页方式,实现PaginatedList接口來控制分页和排序, 不能通过在页面tag中的那个pageSize来设定每页的记录个数, 搞得每个列表的pageSize都是相同的。估计能够通过修改那个TableTag来实现。(针对TableTag做改造,本来想实现PaginatedList根据TableTag的pagesize进行分页, 后来才发现TableTag是页面的内嵌tag,运行在PaginatedList执行之后,因此肯定是拿不到里面的pagesize的,除非将PaginatedList的执行也放到tag中,这样就成了一个真正的tag组件了)
资源下载链接为: https://pan.quark.cn/s/3d8e22c21839 随着 Web UI 框架(如 EasyUI、JqueryUIExt、DWZ 等)的不断发展与成熟,系统界面的统一化设计逐渐成为可能,同时代码生成器也能够生成符合统一规范的界面。在这种背景下,“代码生成 + 手工合并”的半智能开发模式正逐渐成为新的开发趋势。通过代码生成器,单表数据模型以及一对多数据模型的增删改查功能可以被直接生成并投入使用,这能够有效节省大约 80% 的开发工作量,从而显著提升开发效率。 JEECG(J2EE Code Generation)是一款基于代码生成器的智能开发平台。它引领了一种全新的开发模式,即从在线编码(Online Coding)到代码生成器生成代码,再到手工合并(Merge)的智能开发流程。该平台能够帮助开发者解决 Java 项目中大约 90% 的重复性工作,让开发者可以将更多的精力集中在业务逻辑的实现上。它不仅能够快速提高开发效率,帮助公司节省大量的人力成本,同时也保持了开发的灵活性。 JEECG 的核心宗旨是:对于简单的功能,可以通过在线编码配置来实现;对于复杂的功能,则利用代码生成器生成代码后,再进行手工合并;对于复杂的流程业务,采用表单自定义的方式进行处理,而业务流程则通过工作流来实现,并且可以扩展出任务接口,供开发者编写具体的业务逻辑。通过这种方式,JEECG 实现了流程任务节点和任务接口的灵活配置,既保证了开发的高效性,又兼顾了项目的灵活性和可扩展性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值