struts2标签–sort(排序)



6struts2标签–sort(排序)

package com.tag;

import java.util.Comparator;

public class MyComparator implements Comparator{

public int compare(Object o1, Object o2) {
return ((String)o1).length() – ((String)o2).length();
}
}

 

<%@ page contentType=”text/html; charset=UTF-8″ %>
<%@ taglib prefix=”s” uri=”/struts-tags” %>

<s:bean name=”com.tag.MyComparator” id=”myComparator” />


<table border=”1″ width=”200″>
<s:sort source=”{‘java培训基础’, ‘spring2.0宝典’, ‘清量级J2EE企业应用实战’, ‘AJAX’, ‘webwork’, ‘J2EE哈哈’}”
comparator=”#myComparator”>

<s:iterator status=”st”>
<tr <s:if test=”#st.odd”>style=”background-color:#bbbbbb”</s:if>>
<td nowrap=”nowrap”><s:property /></td>
</tr>
</s:iterator>

</s:sort>
</table>

 

运行结果:

 

AJAX
J2EE哈哈
webwork
java培训基础
spring2.0宝典
清量级J2EE企业应用实战

http://blog.163.com/ky_199/blog/static/143176020096248222456/