`
qxmcool
  • 浏览: 90826 次
  • 性别: Icon_minigender_1
  • 来自: 石家庄
社区版块
存档分类
最新评论

displaytag

    博客分类:
  • jsp
阅读更多



displaytag的配置方法

第一

在要分页的jsp页面中把编译命令复制进去

<%@ taglib uri="http://displaytag.sf.net" prefix="display"%>

第二

将所有的jar和样式表复制到webinfo 下面

第三

</servlet>
      <servlet>
        <servlet-name>DisplaySource</servlet-name>
        <servlet-class>org.displaytag.sample.DisplaySourceServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>DisplaySource</servlet-name>
        <url-pattern>*.source</url-pattern>
    </servlet-mapping>

    <mime-mapping>
        <extension>css</extension>
        <mime-type>text/css</mime-type>
    </mime-mapping>
   
     <error-page>
        <error-code>404</error-code>
        <location>/404.jsp</location>
</error-page>
   
    复制到web.xml 下面
   
    第四 分页代码
   
    <html>
  <head>
    <title>分页显示</title>
<link rel="stylesheet" type="text/css" href="/css/alternative.css">
  </head>
 
  <body>
  <display:table name="test" pagesize="2" requestURI="/manyPage.do" class="print">
  <display:column property="id" title="编号" />
  <display:column property="name" title="产品名称"/>
  </display:table>
  </body>
</html>

第五displaytag_zh_CN.properties文件

#Generated by ResourceBundle Editor (http://eclipse-rbe.sourceforge.net)

export.csv         = true
export.excel.class = org.displaytag.export.excel.DefaultHssfExportView
export.pdf.class   = org.displaytag.export.DefaultPdfExportView
export.rtf.class   = org.displaytag.export.DefaultRtfExportView
export.types       = csv excel xml pdf rtf
export.xml         = true

paging.banner.first            = <span class="pagelinks">\r\n[\u6700\u524D/\u4E0A\u4E00\u9875] {0}\r\n[<a href="{3}">\u4E0B\u4E00\u9875</a>\r\n/<a href="{4}">\u6700\u540E</a>]\r\n</span>
paging.banner.full             = <span class="pagelinks">[<a href="{1}">\u4E0A\u4E00\u9875</a>/<a href="{2}">\u4E0B\u4E00\u9875</a>]{0}[<a href="{3}">\u5F00\u59CB</a>/<a href="{4}">\u6700\u540E</a>]</span>
paging.banner.last             = <span class="pagelinks">\r\n[<a href="{1}">\u6700\u524D</a>\r\n/<a href="{2}">\u524D\u4E00\u9875</a>]\r\n{0} [\u4E0B\u4E00\u9875/\u6700\u540E]\r\n</span>
paging.banner.some_items_found = <span class="pagebanner">\r\n{0}\u6761\u8BB0\u5F55,\r\n\u663E\u793A {2} \u5230{3}\u6761\u8BB0\u5F55.\r\n</span>

第六改变样式

<style type="text/css" media="all">
@import url("css/teststyles.css");
</style>



displaytag的配置方法

第一

在要分页的jsp页面中把编译命令复制进去

<%@ taglib uri="http://displaytag.sf.net" prefix="display"%>

第二

将所有的jar和样式表复制到webinfo 下面

第三

</servlet>
      <servlet>
        <servlet-name>DisplaySource</servlet-name>
        <servlet-class>org.displaytag.sample.DisplaySourceServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>DisplaySource</servlet-name>
        <url-pattern>*.source</url-pattern>
    </servlet-mapping>

    <mime-mapping>
        <extension>css</extension>
        <mime-type>text/css</mime-type>
    </mime-mapping>
   
     <error-page>
        <error-code>404</error-code>
        <location>/404.jsp</location>
</error-page>
   
    复制到web.xml 下面
   
    第四 分页代码
   
    <html>
  <head>
    <title>分页显示</title>
<link rel="stylesheet" type="text/css" href="/css/alternative.css">
  </head>
 
  <body>
  <display:table name="test" pagesize="2" requestURI="/manyPage.do" class="print">
  <display:column property="id" title="编号" />
  <display:column property="name" title="产品名称"/>
  </display:table>
  </body>
</html>

第五displaytag_zh_CN.properties文件

#Generated by ResourceBundle Editor (http://eclipse-rbe.sourceforge.net)

export.csv         = true
export.excel.class = org.displaytag.export.excel.DefaultHssfExportView
export.pdf.class   = org.displaytag.export.DefaultPdfExportView
export.rtf.class   = org.displaytag.export.DefaultRtfExportView
export.types       = csv excel xml pdf rtf
export.xml         = true

paging.banner.first            = <span class="pagelinks">\r\n[\u6700\u524D/\u4E0A\u4E00\u9875] {0}\r\n[<a href="{3}">\u4E0B\u4E00\u9875</a>\r\n/<a href="{4}">\u6700\u540E</a>]\r\n</span>
paging.banner.full             = <span class="pagelinks">[<a href="{1}">\u4E0A\u4E00\u9875</a>/<a href="{2}">\u4E0B\u4E00\u9875</a>]{0}[<a href="{3}">\u5F00\u59CB</a>/<a href="{4}">\u6700\u540E</a>]</span>
paging.banner.last             = <span class="pagelinks">\r\n[<a href="{1}">\u6700\u524D</a>\r\n/<a href="{2}">\u524D\u4E00\u9875</a>]\r\n{0} [\u4E0B\u4E00\u9875/\u6700\u540E]\r\n</span>
paging.banner.some_items_found = <span class="pagebanner">\r\n{0}\u6761\u8BB0\u5F55,\r\n\u663E\u793A {2} \u5230{3}\u6761\u8BB0\u5F55.\r\n</span>

第六改变样式

<style type="text/css" media="all">
@import url("css/teststyles.css");
</style>
   


   
Struts中display标签的使用小结

这个是Display Tag的官方网站http://displaytag.sourceforge.net。        首先当然是要下载它的jar包了,这里可以下载到最新的版本。将jar包放到WEB-INF的lib文件夹下。另外还需要两个辅助包:apache的commons-lang和standard包,更多的辅助包可以在这里下载。    在web.xml下添加一个filter    <filter>        <filter-name>exportFilter</filter-name>        <filter-class>org.displaytag.filter.ResponseOverrideFilter</filter-class>    </filter>    在jsp页面做一个引用:<%@ taglib uri="http://displaytag.sf.net/el" prefix="display" %>    首先我们定义一个list<%List test = new ArrayList( 6 );test.add( "Test String 1" );test.add( "Test String 2" );test.add( "Test String 3" );test.add( "Test String 4" );test.add( "Test String 5" );test.add( "Test String 6" );request.setAttribute( "test", test );%>    当我们想在jsp页面上显示这个list时,我们只需要写一句话    <display:table name="test" />    display tag会自动生成一个table    如果list是从控制层抛出来的,name可使用EL表达式表示    <display:table name="${test}" />    这是最简单的display tag的使用,我们可以给它加上样式等,也可以定义显示的列,下面的table显示复杂一些<display:table name="test" styleClass="list" cellspacing="0" cellpadding="0"><display:column property="id" title="ID" class="idcol"/><display:column property="name" /><display:column property="email" /><display:column property="description" title="Comments"/></display:table>    如果想要给它加个链接也很简单,下面的代码给name加了连接,并附带id参数,email也自动连接到mailto:XXX<display:table name="test" styleClass="list" cellspacing="0" cellpadding="0"><display:column property="id" title="ID" class="idcol"/><display:column property="name" url="detail.jsp" paramId="id" paramProperty="id"/><display:column property="email" autolink="true"/><display:column property="description" title="Comments"/></display:table>下面介绍几个Display最常用的功能,更多功能请参考http://displaytag.homeip.net/displaytag-examples-1.1/。1. 分页    如果想对代码分页,只需在display:table标签中添加一项pagesize="每页显示行数",如<display:table name="test" pagesize="10"/>2. 对列排序    display tag可对列进行排序,就是点击列名,对该列的数据进行排序。你只需对想要排序的列添加 sort="true" 就OK,如下面的代码可对前三列进行排序。在display:table中添加defaultsort="列数",可默认对指定的列排序。<display:table name="test" styleClass="list" cellspacing="0" cellpadding="0" defaultsort="1"><display:column property="id" title="ID" class="idcol" sort="true"/><display:column property="name" url="detail.jsp" paramId="id" paramProperty="id" sort="true"/><display:column property="email" autolink="true" sort="true"/><display:column property="description" title="Comments"/></display:table>   如果table有分页,Display Tag默认只对当前页进行排序,如果想对整个list排序,可以在display:table之间添加一段代码:<display:setProperty name="sort.amount" value="list"/>3. 导出数据    在display:table中添加export="true",看看会出现什么!Display Tag默认会提供三种数据导出方式:CSV、Excel、XML 。    另外Display Tag还可以导出为PDF格式,在http://prdownloads.sourceforge.net/itext/下载一个辅助包iText.jar,copy到lib目录下,然后在display:table之间添加一段代码:<display:setProperty name="export.pdf" value="true"/>,大功告成。4. Display Tag的属性设置    前面所说的display:setProperty 是一种改变Display Tag属性的方法,但是在每个jsp中都要写太麻烦了。    Display Tag中设置了很多默认的属性,它有一个专门的属性文件,是在它的jar包中的displaytag/properties/TableTag.properties    想要改变它的默认属性,我们可以在WEB-INF\classes下新建一个文件displaytag.properties,仿照TableTag.properties中属性的格式设置需要修改的属性。    TableTag.properties中的# messages中设置的是显示在页面上的提示信息。默认是英文的,我们可以把它改为中文的。不过这里只能使用unicode,就是说中文字符必须转换为 unicode码,这个可以使用jdk自带的native2ascii.exe进行转换。5. 其它功能    DisplayTag还有一些很实用的小功能,这里提两个。一个是对数据的Format,这是1.1版本添加的新功能,可以使用标签的方式格式化时间、数字、字符串。比如日期,在需要格式化的column标签中添加format="{0,date,yyyy-MM-dd}",第一个参数为格式化的数据序号,第二个参数是数据类型,数字为number,第三个参数为数据格式。    另外一个功能是对table数据的合计功能。在table标签中添加 decorator="org.displaytag.decorator.TotalTableDecorator",然后在想要进行合计的数据列的 column标签中添加 total="true",该列就可以被计算总数了。但这个功能有个缺点,不能用在有分页的时候,它只能合计第一页的数据。DisplayTag的不足    初次使用DisplayTag的人可能会觉得惊喜,但是用久了会发现很多问题,最大的问题是对中文的支持不好,比如如果查询条件中有中文,就无法翻页,无法对中文排序,将中文导出为指定文件时出现乱码等等。这些问题有时候会让人很郁闷,有时候逼得你要去修改它的源代码。下面是对以上几个问题的解决方法:    1. 对于中文无法翻页、排序,最简单的办法是修改Tomcat下的server.xml文件。找到HTTP的Connector标签,在里面添加一项 URIEncoding="...",引号里面的内容取决于你的页面编码,比如可以是GBK,UTF8等。这样上面两个问题就可以解决了。    2. 导出为文件:其实这个功能除了中文支持外还有很多其它问题,比如它会将Html标签一起导出、只导出显示的内容,但如果对table进行了 decorator,decorator后的内容无法导出。如果想要将中文正确导出,需要修改DisplayTag源代码。    下载相同版本的源代码,在org.displaytag.export.ExcelView.java文件中找到getMimeType()方法,将此方法修改为 return "application/vnd.ms-excel;charset=GB2312";,修改后导出数据的速度会慢很多,不过将就吧。    3. 新版的DisplayTag1.1添加了对一次取部分数据的支持,相关的标签包括partialList和size,需要设置partialList="true"和size的大小。具体怎么用偶还没研究。DisplayTag是一个非常好用的表格显示标签,适合MVC模式,其主页在http://displaytag.sourceforge.net一、最简单的情况,未使用<display:column/>标签<%request.setAttribute( "test", new ReportList(6) );%><display:table name="test" />标签遍历List里的每一个对象,并将对象里的所有属性显示出来。一般用于开发的时候检查对象数据的完整性。二、使用<display:column/>标签的情况<display:table name="test"><display:column property="id" title="ID" /><display:column property="name" /><display:column property="email" /><display:column property="status" /><display:column property="description" title="Comments"/></display:table>property对应List里对象的属性(用getXXX()方法取得),title则对应表格表头里的列名。定义列有两种方式:A、<display:column property="email" />使用<display:column/>标签里的property属性来定义B、<display:column title="email">email@it.com</display:column>在<display:column/>标签体里增加内容,可以是常量,也可以用其他标签等等两种方式比较,用property属性来定义更加快速和利于排序。三、表格显示样式的定义A、在<display:table/>和<display:column/>标签里指定标准的html属性,烦琐B、修改样式表<display:table name="test" class="mars"><display:column property="id" title="ID" class="idcol"/><display:column property="name" /><display:column property="email" /><display:column property="status" class="tableCellError" /><display:column property="description" title="Comments"/></display:table>通过class属性来指定所要应用的样式。可以在其默认样式表里(./css/screen.css)直接修改四、标签取得数据的数据源有四种范围pageScoperequestScope (默认) <display:table name="test2" >sessionScope <display:table name="sessionScope.holder.list" > 注意,这里要指定范围,非默认applicationScope五、通过增加id属性创建隐含的对象<display:table name="test" id="testit"><display:column property="id" title="ID" /><display:column property="name" /><display:column title="static value">static</display:column><display:column title="row number (testit_rowNum)"><%=pageContext.getAttribute("testit_rowNum")%></display:column><display:column title="((ListObject)testit).getMoney()"><%=((ListObject)pageContext.getAttribute("testit")).getMoney()%></display:column></display:table>注意到在<display:table/>里增加了id属性,这时就在page context里创建了一个隐含对象,指向List里的当前对象,可以通过(ListObject)pageContext.getAttribute("id")来捕获这个对象。同时还创建了一个id_rowNum对象,同样,可通过pageContext.getAttribute("testit_rowNum")来捕获,它仅仅代表当前行的行数。有了这两个隐含对象,就可以通过其他标签来访问,例如Jstl:<display:table id="row" name="mylist"><display:column title="row number" ><c:out value="${row_rowNum}"/></display:column><display:column title="name" ><c:out value="${row.first_name}"/><c:out value="${row.last_name}"/></display:column></display:table>六、显示部分数据显示开始五条数据:通过设定length属性<display:table name="test" length="5"><display:column property="id" title="ID" /><display:column property="email" /><display:column property="status" /></display:table>显示第三到第八条数据:通过设定offset和length属性<display:table name="test" offset="3" length="5"><display:column property="id" title="ID" /><display:column property="email" /><display:column property="status" /></display:table>七、对email和url地址的直接连接<display:table name="test" ><display:column property="id" title="ID" /><display:column property="email" autolink="true" /><display:column property="url" autolink="true" /></display:table>如果要显示的对象里包含email和url地址,则可以在display:column里直接设定autolink="true"来直接连接八、使用装饰模式转换数据显示(写自己的 decorator )A、对整个表格应用decorator<display:table name="test" decorator="org.displaytag.sample.Wrapper" ><display:column property="id" title="ID" /><display:column property="email" /><display:column property="status" /><display:column property="date" /><display:column property="money" /></display:table>org.displaytag.sample.Wrapper即自己写的decorator,它要继承TableDecorator类,看看它的一个方法:public String getMoney(){return this.moneyFormat.format(((ListObject) this.getCurrentRowObject()).getMoney());}很明显,它通过父类的getCurrentRowObject()方法获得当前对象,然后对其getMoney()方法进行‘油漆’B、对单独的column应用decorator<display:table name="test"><display:column property="id" title="ID" /><display:column property="email" /><display:column property="status" /><display:column property="date" decorator="org.displaytag.sample.LongDateWrapper" /></display:table>org.displaytag.sample.LongDateWrapper要实现ColumnDecorator接口,它的方法:public final String decorate(Object columnValue){Date date = (Date) columnValue;return this.dateFormat.format(date);}显然,它获得不了当前对象(因为它实现的是接口),仅仅是获得该对象的columnValue,然后‘油漆’九、创建动态连接有两种方法创建动态连接:A、在<display:column/>里通过增加href、paramId、paramName、paramScope、paramProperty属性href       基本的URL 地址paramId     加在URL 地址后的参数名称paramName    数据bean的名称,一般为null(即使用当前List里的对象)paramScope    数据bean的范围,一般为nullparamProperty  数据bean的属性名称,用来填充URL 地址后的参数值<display:table name="sessionScope.details"><display:column property="id" title="ID" href="details.jsp" paramId="id" /><display:column property="email" href="details.jsp" paramId="action" paramName="testparam" paramScope="request" /><display:column property="status" href="details.jsp" paramId="id" paramProperty="id" /></display:table>这种方法简便直接,但缺点是无法产生类似details.jsp?id=xx&action=xx的复合URLB、应用decorator 创建动态连接:<display:table name="sessionScope.details" decorator="org.displaytag.sample.Wrapper" ><display:column property="link1" title="ID" /><display:column property="email" /><display:column property="link2" title="Actions" /></display:table>org.displaytag.sample.Wrapper里的方法:public String getLink1(){ListObject lObject= (ListObject)getCurrentRowObject();int lIndex= getListIndex();return "<a href=\"details.jsp?index=" + lIndex + "\">" + lObject.getId() + "</a>";}public String getLink2(){ListObject lObject= (ListObject)getCurrentRowObject();int lId= lObject.getId();return "<a href=\"details.jsp?id=" + lId+ "&action=view\">View</a> | "+ "<a href=\"details.jsp?id=" + lId+ "&action=edit\">Edit</a> | "+ "<a href=\"details.jsp?id=" + lId+ "&action=delete\">Delete</a>";}十、分页实现分页非常的简单,增加一个pagesize属性指定一次想显示的行数即可<display:table name="sessionScope.test" pagesize="10"><display:column property="id" title="ID" /><display:column property="name" /><display:column property="email" /><display:column property="status" /></display:table>十一、排序排序实现也是很简单,在需要排序的column里增加sortable="true"属性,headerClass="sortable"仅仅是指定显示的样式。column里的属性对象要实现Comparable接口,如果没有的话可以应用decoratordefaultsort="1"       默认第一个column排序defaultorder="descending"  默认递减排序<display:table name="sessionScope.stest" defaultsort="1" defaultorder="descending"><display:column property="id" title="ID" sortable="true" headerClass="sortable" /><display:column property="name" sortable="true" headerClass="sortable"/><display:column property="email" /><display:column property="status" sortable="true" headerClass="sortable"/></display:table>注意的是,当同时存在分页时排序仅仅针对的是当前页面,而不是整个List都进行排序十二、column 分组分组只是需要在column里增加group属性<display:table name="test" class="simple"><display:column property="city" title="CITY" group="1"/><display:column property="project" title="PROJECT" group="2"/><display:column property="amount" title="HOURS"/><display:column property="task" title="TASK"/></display:table>十三、导出数据到其他格式(页面溢出filter??)在<display:table/>里设定export="true"在<display:column/>里设定media="csv excel xml pdf" 决定该字段在导出到其他格式时被包不包含,不设定则都包含<display:setProperty name="export.csv" value="false" />决定该种格式能不能在页面中导出<display:table name="test" export="true" id="currentRowObject"><display:column property="id" title="ID"/><display:column property="email" /><display:column property="status" /><display:column property="longDescription" media="csv excel xml pdf" title="Not On HTML"/><display:column media="csv excel" title="URL" property="url"/><display:setProperty name="export.pdf" value="true" /><display:setProperty name="export.csv" value="false" /></display:table>十四、配置属性,覆盖默认两种方法:A、在程序classpath下新建displaytag.properties文件B、对于单个表格,应用<display:setProperty>标签具体可配置的属性:http://displaytag.sourceforge.net/configuration.html十五、一个完整的例子<display:table name="test" export="true" sort="list" pagesize="8"><display:column property="city" title="CITY" group="1" sortable="true" headerClass="sortable"/><display:column property="project" title="PROJECT" group="2" sortable="true" headerClass="sortable"/><display:column property="amount" title="HOURS"/><display:column property="task" title="TASK"/></display:table>















<?xml version="1.0" encoding="GBK"?> <!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd"> <taglib> <tlib-version>1.1</tlib-version> <jsp-version>1.2</jsp-version> <short-name>display</short-name> <uri>http://displaytag.sf.net</uri> <display-name>Display *: Tag Library</display-name> <description> The display tag library is an open source suite of custom tags that provide high level web presentation patterns which will work in a MVC model, and provide a significant amount of functionality while still being simple and straight-forward to use. The primary tag in the library is the Table tag. </description> <tag> <name>table</name> <tag-class>org.displaytag.tags.TableTag</tag-class> <tei-class>org.displaytag.tags.TableTagExtraInfo</tei-class> <body-content>JSP</body-content> <display-name>table</display-name> <description> 在jsp中显示出一个表格,此表格可以通过定义属性来获得数据库中的表,可以分页排序的显示出来,还可以将表中的数据以 CSV,Excel,和XML的格式生成。 </description> <attribute> <name>list</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <description> 参考表格中使用的源对象,可以表示一个请求对象范围的特性,你必须定义一个name属性或list属性,使用Name来暗示。 </description> </attribute> <attribute> <name>name</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <description> 指定范围属性的名称,在标准标签库中必须有一个name标签来指向源对象 (request.setAttribute("test", (java.util.List) sqldb.getData()) //@*name="test"), sqldb.getData()是在数据库中取出的所有记录 </description> </attribute> <attribute> <name>length</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>int</type> <description> 设置显示在表格中的记录数(//@*length="5") </description> </attribute> <attribute> <name>offset</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>int</type> <description> 设置从用户输入的索引值,显示索引值后的所有记录(//@*offset="3") </description> </attribute> <attribute> <name>pagesize</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>int</type> <description> 用户输入表格每页显示的记录数,使表中的纪录分页显示((//@*pagesize="6") </description> </attribute> <attribute> <name>decorator</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>java.lang.String</type> <description> 使用装饰模式转换数据显示,用户可以自己写decorator。 </description> </attribute> <attribute> <name>requestURI</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>java.lang.String</type> <description> 在struts中,当设置了排序后,点击表头,它会指向你转向的jsp,如果想跳转到servlet,action,或者其他页面, 可以通过requestURI设置跳转地址。 </description> </attribute> <attribute> <name>style</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>java.lang.String</type> <description>HTML通用属性。</description> </attribute> <attribute> <name>class</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>java.lang.String</type> <description> 为表格定义样式.这里有五种样式:isis,its,mars,simple,report,mark,但要引入screen.css样式表. </description> </attribute> <attribute> <name>cellspacing</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>java.lang.String</type> <description>HTML通用属性,表格中单元格的边距</description> </attribute> <attribute> <name>cellpadding</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>java.lang.String</type> <description>HTML通用属性,设置单元格沿四边的大小宽度,比在style或class中使用"padding"更好.</description> </attribute> <attribute> <name>frame</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>java.lang.String</type> <description>HTML通用属性.</description> </attribute> <attribute> <name>rules</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>java.lang.String</type> <description>HTML通用属性.</description> </attribute> <attribute> <name>summary</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>java.lang.String</type> <description>HTML通用属性</description> </attribute> <attribute> <name>htmlId</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>java.lang.String</type> <description>html中"id"通用属性 </description> </attribute> <attribute> <name>export</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>boolean</type> <description> 设置能否导出:Excel,XML,CSV文件,为true时可以导出. (//@*export="true") </description> </attribute> <attribute> <name>id</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>java.lang.String</type> <description> 添加id属性,同时就在pageContext里创建了一个隐含对象,指向list里的当前对象可以通过 (ListObject)pageContext.getAttribute("id")来捕获这个对象。同时还创建了一个id_rowNum对象,同样,可 通过pageContext.getAttribute("testit_rowNum")来捕获,它仅仅代表当前行的行数。 </description> </attribute> <attribute> <name>sort</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>java.lang.String</type> <description> 输入'list'并在列属性中sortable为true的情况下,则按照表中所有记录进行排序(//@*sort="list"). </description> </attribute> <attribute> <name>defaultsort</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>int</type> <description> 按照索引列的序号进行排序(//@*defaultsort="1"表示第一列). </description> </attribute> <attribute> <name>defaultorder</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>java.lang.String</type> <description> 对指定索引列的序号(defaultsort属性)进行"升序(ascending)"(默认)或"降序(descending)",(//@*defaultorder="descending")。 </description> </attribute> <attribute> <name>partialList</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>boolean</type> <description>能否显示集合的一部分,有效的值是true或false(//@*partialList="true")</description> </attribute> <attribute> <name>size</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <description> 当partialList为true时才能使用,是写入一个整型对象,它是包含总数据集大小的,要用方法给整数赋予属性 (request.setAttribute("sum",new Integer(count))),count是数据库中所有记录总数,sum是属性名,在size属性中 这样写://@*size="sum". </description> </attribute> <example> <![CDATA[ <display:table name="someList" export="true" id="row" requestURI="MyAction.do"> <display:column sortable="true" title="ID"> <c:out value="${row.id}"/> </display:column> <display:column property="email" autolink="true"/> <display:column property="description" title="Comments"/> </display:table> ]]> </example> </tag> <tag> <name>column</name> <tag-class>org.displaytag.tags.ColumnTag</tag-class> <body-content>JSP</body-content> <display-name>column</display-name> <description> 在表格内显示一个烈的属性,必须在table标签内;其属性名决定决定显示列的内容, 如果属性为空,则在jsp页面中没有显示。 </description> <attribute> <name>property</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>java.lang.String</type> <description> 此属性名是用来显示列中记录的,属性名是pojo类(bean类)中的属性。 (//@*property="job_id" job_id是pojo类中的一个属性) </description> </attribute> <attribute> <name>title</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>java.lang.String</type> <description>列中的标题,列头(//@*title="名称")</description> </attribute> <attribute> <name>comparator</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <description> The classname of comparator to use when sorting this column, or the comparator itself. Defaults to the DefaultComparator. </description> </attribute> <attribute> <name>total</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>boolean</type> <description> 在table标签中添加 decorator="org.displaytag.decorator.TotalTableDecorator", 然后在想要进行合计的数据列的 column标签中添加 //@*total="true",该列就可以被计算总数了。 </description> </attribute> <attribute> <name>sortable</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>boolean</type> <description>此属性如果设置为真那么此列可以排序默认为假(//@*sortable="true").</description> </attribute> <attribute> <name>defaultorder</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>java.lang.String</type> <description> 默认为此列排序,有效值为升序(默认)和降序(//@*defaultorder="ascending" 或 //@*defaultorder="descending") </description> </attribute> <attribute> <name>autolink</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>boolean</type> <description> 如果要显示的对象里包含email和url地址,则可以在display:column里直接设定autolink="true"来直接连接,默认为false. </description> </attribute> <attribute> <name>format</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>java.lang.String</type> <description> 可以使用标签的方式格式化时间、数字、字符串。比如日期,在需要格式化的column标签中添加 //@*format="{0,date,yyyy-MM-dd}",第一个参数为格式化的数据序号, 第二个参数是数据类型,数字为number,第三个参数为数据格式。 </description> </attribute> <attribute> <name>href</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>java.lang.String</type> <description> 创建动态连接,基本的URL地址,等价于HTML中的href但不能传参。 </description> </attribute> <attribute> <name>url</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>java.lang.String</type> <description> 基于url的动态链接,等同于HTML中的href(//@*url="index.jsp"). </description> </attribute> <attribute> <name>paramId</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>java.lang.String</type> <description> 加在href属性的URL地址后的参数名称(//@*paramId="id" 等同于HTML中的 a href="index.jsp?id"的id参数)。 </description> </attribute> <attribute> <name>paramName</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>java.lang.String</type> <description> 加在href属性的URL地址后的参数值(//@*paramName="name" 等同于HTML中的 a href="index.jsp?id=name" id对应的name值)。 </description> </attribute> <attribute> <name>paramProperty</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>java.lang.String</type> <description> 数据bean的属性名称,用来填充href属性的URL地址后的参数值(//@*paramProperty="job_id" job_id是pojo类中的属性) display:column href="baseurl" paramId="paramid" paramProperty="propertyname" http://baseurl/paramid=名字为propertyname的属性值。 </description> </attribute> <attribute> <name>paramScope</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>java.lang.String</type> <description> 设置paramid后边的的名称,此名称为范围内的名字为paramName的值, (display:column href="baseurl" paramId="paramid" paramName="name" paramScope="scope" 写成HTML是:http://baseurl/paramid=scope) </description> </attribute> <attribute> <name>maxLength</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>int</type> <description> 如果此属性存在,那么列的字符仅被显示用户定义的字符数, 然后加上。。。(//@*maxLength="10" 如果在备注这列加上其属性,那么备注的字段只显示10个字符和。。。) 当鼠标划过的时候显示其全部内容 </description> </attribute> <attribute> <name>maxWords</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>int</type> <description> 如果此属性存在,那么列仅被显示用户定义的单词数,然后加上。。。 (//@*maxWords="2" 如果在备注这列加上其属性,那么备注的字段只显示2个单词加。。。) 当鼠标划过的时候显示其全部内容 </description> </attribute> <attribute> <name>class</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>java.lang.String</type> <description> HTML通用属性,设置列的样式。 </description> </attribute> <attribute> <name>headerClass</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>java.lang.String</type> <description>"class"html中的属性仅能加在头单元格内</description> </attribute> <attribute> <name>style</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>java.lang.String</type> <description>HTML通用属性,设置列的样式。</description> </attribute> <attribute> <name>group</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>int</type> <description> display:column property="city" title="CITY" group="1" display:column property="project" title="PROJECT" group="2" 这样不仅仅结果可以分组,而且还可以省略掉重复的数据,例如city列,project列都有 A ,B ,A,B 两行那么第二行这两列就不显示了。 同样只能对当前页进行分组。 注意:第一列一定要1,第二列一定是2,否则出NUllPoint 错误。 </description> </attribute> </tag> </taglib> 






































displaytag这个怎么能调出样式啊
没有导入 displaytag的css文件,你要在你jsp页面中导入 或者在你的配置文件中导入 只要导入以下文件,问题就会解决 <style type="text/css" media="all"> @import url("css/maven-base.css"); @import url("css/maven-theme.css"); @import url("css/site.css"); @import url("css/screen.css"); </style>









1、 Displaytag提供的默认的系统提示均为英文,有两种方法进行汉化:
1)、将displaytag-1.1.1.jar中自带的org/displaytag/properties/displaytag.properties 文件拷贝到项目的classes目录下
用java提供的native2ascii工具将文件进行汉化,汉化后的内容重新保存为displaytag.properties文件
2)、将jar包中的displaytag.properties汉化后替换jar包中原来的文件

2、 <display:column property="email" /> //property指定了列表中包含的bean(actionForm或vo)中包含的属性的名称,大小写必须一致
<display:column title="email">email@it.com</display:column> //列表中指定任意的列,不包含在bean中,比如显示按钮、图片等

3、 先来给出第一个具体的例子(实现列包装:显示一列checkbox,点击标题栏的checkbox完成全选):
<display:column style="width:5%;text-align:center"
headerClass="dataHead" property="columnId"
title="<input type='checkbox' name='checkall' value='all'onclick='checkAll();' />"decorator="ainx.asiainfo.common.displaytag.CheckboxColumnWrapper" />
从该例可以看出:
1)、title属性定义了一个checkbox,点击后执行javascript函数checkAll()完成对checkbox的全选,该checkbox显示在该列的标题栏中
2)、headerClass属性指定了标题栏的css样式,dataHead是已经在css文件中定义了的
3)、property属性指定该列将要显示bean中的哪个变量的内容,大小写必须与bean中的定义一致
4)、各行都用了一个decorator将数据进行了包装,由ainx.asiainfo.common.displaytag.CheckboxColumnWrapper类实现了对该列数据的包装,该类具体内容如下:
package ainx.asiainfo.common.displaytag;
import javax.servlet.jsp.PageContext;
import org.displaytag.decorator.DisplaytagColumnDecorator;
import org.displaytag.exception.DecoratorException;
import org.displaytag.properties.MediaTypeEnum;

/**
* 用于丰富displaytag列显示的功能,在表格中显示一列checkbox
* @author lvping
*/
public class CheckboxColumnWrapper implements DisplaytagColumnDecorator {
/**
* 该列全部显示为checkbox,其value为该列带有的ID
*/
public Object decorate(Object arg0, PageContext arg1, MediaTypeEnum arg2) throws DecoratorException {
//arg0表示被包装的该列定义的property属性给定的值
//arg1表示pagecontext
//arg2表示……
String elementid = (String) arg0;
return "<input name=\"selected\" type=\"checkbox\" value=\""+elementid+"\" />";
//同理如果对于该列要显示为一个图片,可以返回”<input type=’image’ src=’…’ />”
}
}

4、 再给出第二个例子(前台分页+排序+分组功能):
<display:table class="data" cellpadding="0" sort="list"requestURI="/NetXpert/room/idcRoomAreaAction.do?actionType=doListIdcArea"pagesize="20" cellspacing="0" style="width:98%" name="areas">
<display:column property="roomname" sortable="true" group="1" title="所在机房"/>
</display:table>
从该例看出:
1)、table中的name属性指定了该表格的数据来自request的attribute中名称为"areas"的数据(即action中必须有如下的代码:
ArrayList alAreas = ……; //此处获取将要在列表中显示的数据
request.setAttribute("areas",alAreas);)
1)、table中的pagesize设定了表格中每页显示的记录个数
2)、table中的requestURI属性定义了每次分页时需要提交的请求
3)、table中的sort属性设为list,表示点击表中某列排序时可对整个表格排序
(Use 'page' if you want to sort only visible records, or 'list' if you want to sort the full list, or 'external' if the data is sorted outside displaytag)
4)、sortable属性设为true,则表示对该列支持排序(前台排序),显示出的该列的标题上会自动带有下划线,点击可排序
5)、group属性的设置表示对该列的数据自动分组,设为1表示该列数据为显示出的第一个分组

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics