`

displaytag 外部排序

阅读更多

  大家都知道,Display标签处理大数据量的时候,排序会反应迟顿。因此标签的设计者提供了外部排序功能,也就是由用户自己来处理排序逻辑,我参照字面及实际的意思,将external译为外部排序,好象不太准确,谁有更好的译法,请告诉我。
  这是Display官方文档的译文,第一次翻译E文,不妥之处见谅。特意以中英文对照的形式,大家对照着来理解。有两句话没有译出来,谁知道怎么译请告诉我。
  

The default behavior of displaytag is working with a full list, handling sorting and paging trasparently. Sometimes, however, you could need to give displaytag only the records displayed, handling sorting and paging by yourself (this is what we call "partial list support").
displaytag标签的默认行为是使用全部的数据列表,透明的进行排序与分页。可是有时,你可能需要displaytag标签仅显示需要显示的数据,自己来处理排序与分页(这我们称之为“部分列表支持”(这个译法可能不太贴切,大家明白就行,也就是仅使用全部数据列表中的))。

Displaytag 1.1 offers two alternative ways for working with partial lists:
Displaytag 1.1版提供两种可选的方式来处理部分列表支持:

displaytag

the first one uses the valuelist pattern, and requires that the object that you give to displaytag implements the org.displaytag.pagination.PaginatedList interface. You can pass this object to displaytag as an usual list, and it will extract paging and sorting information from it. This way is more recommended if you have to build your backend layer and you can easily follow this pattern.
第一种使用valuelist模式,要求传递给Displaytag标签的对象实现org.displaytag.pagination.PaginatedList接口。这个对象可以象一个一般的数据列表一样传递给Displaytag标签,Displaytag标签将从中提取分页信息及排序信息。如果自己要构建服务端,这种模式是易于使用的,推荐采用。
a second way, recommended if you only have to use partial list for few tables that show a performance problem using full lists, is passing all the needed parameters as separate tag attributes (recors to be shown, page number, total number of records...)
第二种方式,在由于性能问题,仅需使用部分列表显示为数不多的几个表情况下,推荐采用。传递所有需要的参数作为分开的标签属性(如:页码、记录总数)。


Using the Valuelist pattern
Valuelist模式
If the object passed to the displaytag as a list is in fact an instance of org.displaytag.pagination.PaginatedList (and not a collection), displaytag will assume that the list is externally sorted and paginated. Implementing this interface is trivial, and an adapter over existing classes can easily be written. See the org.displaytag.pagination.PaginatedList javadocs for more details.
如果传递给displaytag标签的列表实际上是org.displaytag.pagination.PaginatedList的实例(也就是不是集合),标签会认为这个列表是外部排好序、分好页的。如何实现org.displaytag.pagination.PaginatedList接口就没有必要介绍了,可以很容易的根据已经存在的类改写。可以查看javadocs的相关部分了解更多细节。

In order for the generated pagination and sort links to be "understandable" by the application, they are not generated the same way as for a traditional DisplayTag table. Indeed, since the table is externally sorted and paginated, the application must be able to easily get the sort and pagination parameters, without having to decode the DisplayTag encoded parameters.
这种模式下,为了产生可被应用“理解”的分页及排序链接,使用与传统DisplayTag表格不同的方法。实际上,既然由外部排序与分页,应用必须能够容易地得到排序与分页参数,而不是去解码由标签编码的参数。

These sort and pagination links are generated based on additional properties. These properties can be overridden using, in order to be able to have different sort of page parameters in the application, or to have multiple tables in a single HTML page.
排序及分页的链接是基于额外的属性。这些参数可以使用<display:setProperty/>改写,以便能在一个HTML页面中处理不同的排序参数,或者处理多个表

If the default values of these properties are used, the href of the sort links will look like this:
如果这些属性能缺省值,排序链接地址形式如下所示:


http://foo.bar.com/context/requestUri?sort=name&dir=asc&originalParameters=originalValues.
The href of the pagination links will look like this:
分页链接地址形式如下:
http://foo.bar.com/context/requestUri?sort=name&dir=asc&page=5&originalParameters=originalValues

Without implementing the PaginatedList interface
不实现PaginatedList接口的解决办法


External sort
外部排序

<display:table name="testList" sort="external" defaultsort="1" id="element">
<display:column property="id" title="ID" sortable="true" sortName="id" />
<display:column property="firstName" sortable="true" sortName="firstName" title="First Name" />
<display:column property="lastName" sortable="true" sortName="lastName" title="Last Name" />
<display:column property="address" sortable="true" sortName="address" title="Email Address"/>
</display:table>
When using the sort="external" property you are telling DisplayTag that your list is already sorted according to some specific column before the tag gets it. This is a must when used with partial lists as we will see below, however you can use it by itself. A new property named sortName has been addeed to the column tag. The purpose of this property is for convenience when writing the backend code that actually does the sorting of the data. For example the header link for the column with property id in the sample code above will render a link containing d-(encoded table id)-s=id. If you remove the sortName property from the column the link will instead contain d-(encoded table id)-s=0, which is the index of the column rather than the name. Once again it is solely for convenience.
使用sort="external"属性,告诉DisplayTag标签在它获取数据列表前,列表已经根据特定的列表排好序了。通过下面的例子可以看到,当使用部分列表的时候这是必须的,但是......(这句话没有搞懂怎么翻译,原文为:however you can use it by itself)。列标签添加了一个新的属性:sortName。这是为了便于后台数据排序代码进行处理。例如,上例中id列的排序链接会包含d-(encoded table id)-s=id,如果不使用sortName属性,排序链接相应的会变为包含d-(encoded table id)-s=0,注意,使用的是列的序号而不是列名。再重申一次,这只是为了方便后台代码的编写。

The first time you access a jsp with a DisplayTag in it, there are two ways for the tag to know how your data is sorted. Firstly it will check for a request parameter d-(encoded table id)-s. If that parameter exists, and its value matches the sortName of one of the declared column tags, then when it is rendered to html it will set the matching column as being sorted. If that parameter does not exist it will examine the defaultsort property of the table tag, if it exists then it will render the corresponding column as sorted. Otherwise no column will be rendered as being sorted. So really you have two options. Set your backend to sort your data based on a set column when there is no request parameter, and set your defaultsort parameter to match that column. Or ensure that all links pointing to your page that houses the DisplayTag have a d-(encoded table id)-s=(column index or sortName) parameter in them.
第一次在页面中使用DisplayTag标签的时候,标签有两种方式知道数据是如何排序的。第一种方式为:检测 d-(encoded table id)-s参数,如果参数存在,并且与某一列的sortName属性一致辞,那么标签就以匹配列为排序列来生成HTML代码。如果参数不存在,就检查缺省的排序列,如果存在就以生成以缺省列进行排序的HTML代码。不满足以上情况,就生成的HTML代码是不以任何列进行排序的。所以你有两个选择,当无request参数的时候,后台代码使用特定的列时行排序,然后defaultsor使用该列为默认排序列;或者使所有构筑DisplayTag标签的链接都包含参数:d-(encoded table id)-s=(column index or sortName)。

To determine the request parameter name for column sorting you can do:
可以通过下面的方法获取request参数的名字:


new ParamEncoder(tableId).encodeParameterName(TableTagParameters.PARAMETER_SORT))
To get the order (ASC/DESC):
获取排序request参数名字的方法为:


new ParamEncoder(tableId).encodeParameterName(TableTagParameters.PARAMETER_ORDER))
Descending is 2, Ascending is 1.
降序为2,升序为1。

 

External Sorting And Paging (Partial Lists)
外部排序与分页(部分列表)

<display:table name="testList" sort="external" defaultsort="1" pagesize="20" id="element" partialList="true" size="resultSize">
<display:column property="id" title="ID" sortable="true" sortName="id" />
<display:column property="firstName" sortable="true" sortName="firstName" title="First Name" />
<display:column property="lastName" sortable="true" sortName="lastName" title="Last Name" />
<display:column property="address" sortable="true" sortName="address" title="Email Address"/>
</display:table>
All of the above information for external sorting applies to partial lists. Additionally there are two new properties on the table tag: partialList and size. To enable partial lists simply set partialList="true" on the table tag. Next you must tell Display Tag the total size of your list since you are only making a specific subset of it available to the tag. You do this by storing the total list size in a java.lang.Integer object and putting it into some scope available to DisplayTag. Then you set size=(name the Integer was stored under) on the table tag. Very easy. It is also important that you specify a pagesize on the table tag. It is also a good idea to set your backend to load a default amount of your list when there are no request parameters, probably the first page worth of data.
上列展示了所有与部分列表外部排序有关的参数。注意,出现了两个新的标签属性:partialList及size。使用部分列表只需简单的设定partialList="true"。接下来,既然你仅使用全部数据的子集,那么必须告诉标签数据列表的中数据的数量。告诉的方法就是,在DisplayTag可以访问到范围(sessionScope、request等),使用java.lang.Integer类型的对象来存储整个数据列表的数量,然后在标签中设定size等于上面存储数量时用的名字。非常容易。表格标签设定pagesize参数也是很重要的。当没有request参数的时候,后台代码装载一个默认的列表数量是个好主意,可能......(这句没有搞懂是什么意思,原文为:probably the first page worth of data)。

To determine the starting record you need to return based on the request parameters provided via Display Tag you can do:
使用Display标签提供的request参数可以得到开始的记录,方法如下:


(Integer.parseInt(request.getParameter((new ParamEncoder(tableId).encodeParameterName(TableTagParameters.PARAMETER_PAGE)))) - 1) * pageSize.
To get the ending record just add pageSize to the above value.
将上面的值加上pageSize就可以得到结束记录。

分享到:
评论

相关推荐

    常用jar包

    标题“常用jar包”指的是在Java开发中经常使用的外部库文件,这些jar包包含了各种预编译的类和方法,方便开发者快速实现特定功能,无需从零开始编写代码。在这个场景中,提到的"Displaytag"是一个开源的Java库,主要...

    Stripes 快速入门 pdf 中文版 下载

    而Stripes通过注解的方式将大部分配置内嵌到Java类中,大大减少了外部配置文件的需求。 - **组件模型**:Struts 1基于Servlet生命周期模型,而Stripes采用了更为灵活的组件模型,使得ActionBean可以更好地封装业务...

    kernel-devel-4.18.0-553.45.1.el8-10.x86-64.rpm

    Rocky Linux 8.10内核包

    Simulink中三阶单环多位量化Σ-Δ调制器的设计与实现-音频带ADC的应用(复现论文或解答问题,含详细可运行代码及解释)

    内容概要:本文档详细介绍了如何在Simulink中设计一个满足特定规格的音频带ADC(模数转换器)。首先选择了三阶单环多位量化Σ-Δ调制器作为设计方案,因为这种结构能在音频带宽内提供高噪声整形效果,并且多位量化可以降低量化噪声。接着,文档展示了具体的Simulink建模步骤,包括创建模型、添加各个组件如积分器、量化器、DAC反馈以及连接它们。此外,还进行了参数设计与计算,特别是过采样率和信噪比的估算,并引入了动态元件匹配技术来减少DAC的非线性误差。性能验证部分则通过理想和非理想的仿真实验评估了系统的稳定性和各项指标,最终证明所设计的ADC能够达到预期的技术标准。 适用人群:电子工程专业学生、从事数据转换器研究或开发的技术人员。 使用场景及目标:适用于希望深入了解Σ-Δ调制器的工作原理及其在音频带ADC应用中的具体实现方法的人群。目标是掌握如何利用MATLAB/Simulink工具进行复杂电路的设计与仿真。 其他说明:文中提供了详细的Matlab代码片段用于指导读者完成整个设计流程,同时附带了一些辅助函数帮助分析仿真结果。

    计算机课后习题.docx### 【计算机科学】研究生入学考试计算机组成原理专项题库设计:考研复习资源集成与优化

    内容概要:该题库专为研究生入学考试计算机组成原理科目设计,涵盖名校考研真题、经典教材课后习题、章节题库和模拟试题四大核心模块。名校考研真题精选多所知名高校的计算机组成原理科目及计算机联考真题,并提供详尽解析,帮助考生把握考研命题趋势与难度。经典教材课后习题包括白中英《计算机组成原理》(第5版)和唐朔飞《计算机组成原理》(第2版)的全部课后习题解答,这两部教材被众多名校列为考研指定参考书目。章节题库精选代表性考题,注重基础知识与重难点内容,帮助考生全面掌握考试大纲要求的知识点。模拟试题依据历年考研真题命题规律和热门考点,精心编制两套全真模拟试题,并附标准答案,帮助考生检验学习成果,评估应试能力。 适用人群:计划参加研究生入学考试并报考计算机组成原理科目的考生,尤其是需要系统复习和强化训练的学生。 使用场景及目标:①通过研读名校考研真题,考生可以准确把握考研命题趋势与难度,有效评估复习成效;②通过经典教材课后习题的练习,考生可以巩固基础知识,掌握解题技巧;③通过章节题库的系统练习,考生可以全面掌握考试大纲要求的各个知识点,为备考打下坚实基础;④通过模拟试题的测试,考生可以检验学习成果,评估应试能力,为正式考试做好充分准备。 其他说明:该题库不仅提供详细的题目解析,还涵盖了计算机组成原理的各个方面,包括计算机系统概述、数据表示与运算、存储器分层、指令系统、中央处理器、总线系统和输入输出系统等。考生在使用过程中应结合理论学习与实践操作,注重理解与应用,以提高应试能力和专业知识水平。

    __UNI__DB9970A__20250328141034.apk.1

    __UNI__DB9970A__20250328141034.apk.1

    minio-rsc-Rust资源

    rust for minio

    4-4-台区智能融合终端功能模块型式规范(试行).pdf

    国网台区终端最新规范

    《基于YOLOv8的化工管道焊缝缺陷检测系统》(包含源码、可视化界面、完整数据集、部署教程)简单部署即可运行。功能完善、操作简单,适合毕设或课程设计.zip

    资源内项目源码是来自个人的毕业设计,代码都测试ok,包含源码、数据集、可视化页面和部署说明,可产生核心指标曲线图、混淆矩阵、F1分数曲线、精确率-召回率曲线、验证集预测结果、标签分布图。都是运行成功后才上传资源,毕设答辩评审绝对信服的保底85分以上,放心下载使用,拿来就能用。包含源码、数据集、可视化页面和部署说明一站式服务,拿来就能用的绝对好资源!!! 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、大作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.txt文件,仅供学习参考, 切勿用于商业用途。

    python源码-1个机器学习相关资源

    一个简单的机器学习代码示例,使用的是经典的鸢尾花(Iris)数据集,通过 Scikit-learn 库实现了一个简单的分类模型。这个代码可以帮助你入门机器学习中的分类任务。

    pyqt离线包,pyqt-tools离线包

    pyqt离线包,pyqt-tools离线包

    《基于YOLOv8的船舶机舱灭火系统状态监测系统》(包含源码、可视化界面、完整数据集、部署教程)简单部署即可运行。功能完善、操作简单,适合毕设或课程设计.zip

    资源内项目源码是来自个人的毕业设计,代码都测试ok,包含源码、数据集、可视化页面和部署说明,可产生核心指标曲线图、混淆矩阵、F1分数曲线、精确率-召回率曲线、验证集预测结果、标签分布图。都是运行成功后才上传资源,毕设答辩评审绝对信服的保底85分以上,放心下载使用,拿来就能用。包含源码、数据集、可视化页面和部署说明一站式服务,拿来就能用的绝对好资源!!! 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、大作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.txt文件,仅供学习参考, 切勿用于商业用途。

    SQL常用日期和时间函数整理及使用示例

    SQL常用日期和时间函数整理及在sqlserver测试示例 主要包括 1.查询当前日期GETDATE 2.日期时间加减函数DATEADD 3 返回两个日期中指定的日期部分之间的差值DATEDIFF 4.日期格式转换CONVERT(VARCHAR(10),GETDATE(),120) 5.返回指定日期的年份数值 6.返回指定日期的月份数值 7.返回指定日期的天数数值

    GSDML-V2.3-Turck-BL20-E-GW-EN-20160524-010300.xml

    GSDML-V2.3-Turck-BL20_E_GW_EN-20160524-010300.xml

    T_CPCIF 0225-2022 多聚甲醛.docx

    T_CPCIF 0225-2022 多聚甲醛.docx

    《基于YOLOv8的智能仓储货物堆码倾斜预警系统》(包含源码、可视化界面、完整数据集、部署教程)简单部署即可运行。功能完善、操作简单,适合毕设或课程设计.zip

    《基于YOLOv8的智能仓储货物堆码倾斜预警系统》(包含源码、可视化界面、完整数据集、部署教程)简单部署即可运行。功能完善、操作简单,适合毕设或课程设计

    蚕豆脱壳机设计.zip

    蚕豆脱壳机设计.zip

    附件2-2:台区智能融合终端入网专业检测单位授权委托书.docx

    台区终端电科院送检文档

    Y6一39一No23.6D离心通风机 CAD().zip

    Y6一39一No23.6D离心通风机 CAD().zip

    django自建博客app

    django自建博客app

Global site tag (gtag.js) - Google Analytics