|
1、何為 extremeTable,又一個開源taglib
extremeTable,開源的jsp 自定義標簽,以表格的形式顯示數(shù)據(jù),當前最新版本為 1.0.1-M1. 它是一個類似display tag,valueList 等開源產(chǎn)品. homepage: http:/// download: http:///projects/extremecomp/ 開源產(chǎn)品作者: Jeff Johnston ,現(xiàn)居住美國,圣路易斯. 六年web應用軟件開發(fā)經(jīng)驗,eXtremeComponents最初的創(chuàng)建者. 負責設計及大部分的編碼。 其它還包括Paul Horn ,eXtremeTree的技術設計, 以及大部分的編碼; 安裝要求 1、Servlet 2.3 或更高 2、 JDK 1.3.1 或更高 最小的Jars需求 PDF 導出要用到的包: 下載解壓到的主要文件包括 [3]tld文件 [4]一組默認樣式及圖片 [5]用以校驗安裝的測試頁面 [6]doc文檔,比較詳細 web.xml 配置 <taglib> <taglib-uri>/tld/extremecomponents</taglib-uri> <taglib-location>/WEB-INF/tld/extremecomponents.tld</taglib-location> </taglib> <filter> <filter-name>eXtremeExport</filter-name> <filter-class>org.extremecomponents.table.filter.ExportFilter</filter-class> </filter> <filter-mapping> <filter-name>eXtremeExport</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>![]()
<%@ page contentType="text/html;charset=GBK"%> <%@ page import="java.util.*"%> <%@ taglib uri="/tld/extremecomponents" prefix="ec" %> <!-- 在本頁要用到jstl--> <%@ taglib prefix="c" uri="http://java./jsp/jstl/core" %> <!--使用include的方式--> <link rel="stylesheet" type="text/css" href="<c:url value="/extremecomponents.css"/>">![]() <% List goodss = new ArrayList(); for (int i = 1; i <= 10; i++)![]() { Map goods = new java.util.HashMap(); goods.put("code", "A00"+i); goods.put("name", "面包"+i); goods.put("status", "A:valid"); goods.put("born", new Date()); goodss.add(goods); } request.setAttribute("goodss", goodss); %> <ec:table collection="goodss" action="${pageContext.request.contextPath}/test.jsp" imagePath="${pageContext.request.contextPath}/images/*.gif" cellpadding="1" title="my bread"> <ec:column property="code"/> <ec:column property="name"/> <ec:column property="status"/> <ec:column property="born" cell="date" format="yyyy-MM-dd"/> </ec:table>
<context-param> <param-name>extremecomponentsResourceBundleLocation</param-name> <param-value>com.itorgan.tags.extreme.extremetableResourceBundle</param-value> </context-param>
extremetableResourceBundle_en_US.properties代碼如下 extremetableResourceBundle_zh_CN.properties如下. 然后在table標簽中增加locale屬性即可切換 <ec:table ……………… ……………… ……………… locale="en_US" >![]() <ec:table ……………… ……………… ……………… locale="zh_CN" >![]()
<ec:table
…………………… saveFilterSort="true" /ec:table> <a href="1.jsp">跳到</a>新建一頁面用于跳轉的頁面 1.jsp <a href="test.jsp?foo=true">Back</a>/ec:table
<div class="eXtremeTable" > <table border="0" cellpadding="0" cellspacing="0" width="100%" > <tr> <td class="title" ><span><!--標題--></span></td> <td align="right" > <table border="0" cellpadding="0" cellspacing="1" class="toolbar" > <tr> <form name="pres_toolbar" action="/extremesite/public/demo/presidents.jsp" > <!--工具欄,包括上一頁,下一頁以及導出--> </tr> <tr> </form> </tr> </table> </td> </tr> </table>![]() <table id="pres" border="0" cellspacing="2" cellpadding="0" width="100%" class="tableRegion" > <tr> <td colspan="6" > <table border="0" cellpadding="0" cellspacing="0" width="100%" > <tr> <td class="statusBar" >43 results found, displaying 1 to 12 </td> <td class="filterButtons" ></td> </tr> </table> </td> </tr> ![]() <form name="pres_filter" action="/extremesite/public/demo/presidents.jsp" > <tr class="filter" id="filter" > <!--過濾條件的input框--> </tr> </form> <tr> <!--tableHead--> </tr> <tbody class="tableBody" > <tr> <!--column--> </tr> </tbody> </table> </div>![]()
public class HeaderCell extends org.extremecomponents.table.cell.HeaderCell![]() ![]() { public final static String TABLE_HEADER = "itoTableHeader"; public final static String TABLE_HEADER_SORT = "itoTableHeaderSort"; }新的樣式代碼: <LINK REL="stylesheet" HREF="<c:url value="/style.css"/>" TYPE="text/css"><ec:table collection="goodss" action="${pageContext.request.contextPath}/test.jsp" imagePath="${pageContext.request.contextPath}/images/*.gif" cellpadding="1" title="my bread" saveFilterSort="true" locale="zh_CN" > <ec:column property="code" title="編號" width="100" styleClass="GridTd"/> <ec:column property="name" title="名稱" width="200" styleClass="GridTd"/> <ec:column property="status" title="狀態(tài)" width="80" styleClass="GridTd"/> <ec:column property="born" title="生產(chǎn)日期" width="100" cell="date" format="yyyy-MM-dd" styleClass="GridTd"/> </ec:table> 效果見下: table.cell_=display table.cell_currency=org.extremecomponents.table.cell.NumberCell table.cell_number=org.extremecomponents.table.cell.NumberCell table.cell_display=org.extremecomponents.table.cell.DisplayCell table.cell_date=org.extremecomponents.table.cell.DateCell當 column 默認使用org.extremecomponents.table.cell.DisplayCell ![]() public class DisplayCell extends BaseCell {![]() ![]() public String html() { HtmlBuilder html = new HtmlBuilder();![]() html.append(startTD());![]() Object value = column.getValue();![]() if (value != null && StringUtils.isNotEmpty(value.toString())) { html.append(value);![]() } else { html.append(" "); }![]() html.append(endTD());![]() return html.toString(); } }![]() ec已其它cell 日期格式化: cell = " date " format = " yyyy-MM-dd " 數(shù)字格式化: cell="currency" format="###,###,##0.00"
public class DemoInput extends BaseCell![]() ![]() { public String html()![]() { Integer rowNum = rowcount; HtmlBuilder html = new HtmlBuilder(); html.append(startTD()); Object value = column.getValue(); HtmlBuilder input = new HtmlBuilder(); input.input("text"); input.name(column.getProperty() + "_" + rowNum); input.value(value.toString()); input.close(); html.append(input.toString()); html.append(endTD()); return html.toString(); } }
table.cell_demoInput =org.extremecomponents.table.cell.DemoInput jsp代碼 <ec:column property="code" title="編號" width="100" cell="demoInput" styleClass="GridTd"/>效果顯示為
<ec:column property="code" title="編號" width="100" styleClass="GridTd"> <input type="text" value="${goodss.code}" name="code_${ROWCOUNT}"> </ec:column>
public class TableTag extends org.extremecomponents.table.tag.TableTag![]() ![]() { //div 的高度 private String height;![]() public String getHeight()![]() { return height; }![]() public void setHeight(String height)![]() { this.height = height; }![]() public void addExtendedAttributes(Attributes attributes)![]() { attributes.addAttribute("height", getHeight()); }![]() ![]() /**//** * set the new attribuer to null - by ito */ public void release()![]() { super.release(); height = null; } }然后就可以通過
![]() private void body(BaseModel model, Column column, boolean isFirstColumn, boolean isLastColumn) { //原來的代碼略 hssfCell.setEncoding(HSSFCell.ENCODING_UTF_16); //解決中文亂碼 //原來的代碼略 }![]() ![]() private void createHeader(BaseModel model) { //原來的代碼略 hssfCell.setEncoding(HSSFCell.ENCODING_UTF_16); //解決中文亂碼 //原來的代碼略 }
|
|
|
來自: nbtymm > 《Servlet&Jsp》