extremecomponents补充说明

<%@ taglib uri="/WEB-INF/extremecomponents.tld" prefix="ec" %>


<ec:table 
	    items="ls" var="obj"
	    action="/PoetryAction?_method=list"
        view="compact"
		imagePath="/admin/images/table/*.gif"
		width="100%"
		rowsDisplayed="5"
		>
		<ec:exportXls fileName="poetry.xls" tooltip="Excel"/>
		<ec:exportPdf
           fileName="poetry.pdf"
           tooltip="Export PDF"
           headerColor="blue"
           headerBackgroundColor="red"
           headerTitle="Presidents"/>	
		<ec:row>	
			<ec:column property="rowcount" cell="rowCount" title="序号" sortable="false"/>
	    	<ec:column property="title" title="标题"/>
	    	<ec:column property="author" title="作者"/>
	    	<ec:column property="create_time" title="录入时间"/>
	    	<ec:column property="null1" title="添加" viewsDenied="pdf,xls">
	    		<a href="#">添加</a>
	    	</ec:column>
	    	<ec:column property="null2" title="修改" viewsDenied="pdf,xls">
	    		<a href="#">修改</a>
	    	</ec:column>
	    	<ec:column property="null3" title="删除" viewsDenied="pdf,xls">
	    		<a href="#">删除</a>
	    	</ec:column>
		</ec:row>
	</ec:table>

 

1. jar包的支持,如果需要添加导出pdf,xls,那么需要将\eXtremeComponents-1.0.1-with-dependencies\lib下面的包全部导入到工程中。

 

2.提交到servlet中,如果查询列表的方法写在doGet方法中,在ec上点击下一页或分页等操作时,出现的是空白页。

查看ec生成的源代码,javascript:document.forms.ec.ec_eti.value='';document.forms.ec.ec_p.value='2';document.forms.ec.setAttribute('action','/PoetryAction?method=list');document.forms.ec.setAttribute('method','post');document.forms.ec.submit()
可以发现请求是post方式,所以应该执行servlet中的doPost方法。(经测试:程序与ec中参数method同名没有关系

后台程序抛出的异常也可以发现:

严重: /PoetryAction?method=list:
java.lang.NullPointerException
 at com.studio502.view.action.PoetryAction.doPost(PoetryAction.java:57)

 

3.extremecomponentsEXT.jar 是扩展包。

在extremetable.properties中定义的:table.view.compact=org.extremecomponents.table.view.UserCompactView

table.view.html=org.extremecomponents.table.view.UserHtmlView

及ec标签中定义的: view="compact",否则会报类找不到异常。

 

exportPdf.userconfigLocation=/conf/userconfig.xml
exportPdf.font=Simfang

如果上面2行注释了,中文显示不出来,为#号,测试导出中文正确。

conf/userconfig.xml换成本地simfang.ttf,simfang.xml绝对路径。

(详见:extremecomponents pdf 导出中文问题分析 http://simpledev.iteye.com/blog/182944

xls导出支持中文,不会出现乱码。

 

4.代码中的冗余代码(尽管已注释)有的时候存在也是一种错。。。。。。。。。 导致xls,pdf有问题。

<!-- 
		retrieveRowsCallback="limit"
	    filterRowsCallback="limit"
	    sortRowsCallback="limit"
	    		sortable="false"
		filterable="false"
		title="后台用户管理"
		
		
		items="fzAdminUsers" var="fzAdminUser"
	    action="listFzAdminUser.do"
        view="compact" 
		imagePath="../images/table/*.gif"
		width="100%"
		rowsDisplayed="20"
		filterable="false"
		
	<ec:table 
		items="pres"
		action="/admin/test.jsp"
		imagePath="/admin/images/table/*.gif"
		title="Presidents"
		width="60%"
		rowsDisplayed="5"
		>
		<ec:row>
			<ec:column property="name"/>
			<ec:column property="nickname"/>
			<ec:column property="term"/>
		</ec:row>
	</ec:table>
	
	UserHtmlView 类在extremecomponentsEXT.jar中。
	view="compact"  更变样式,抛出的异常信息更明确。
	
	/PoetryAction?_method=list
	 -->

 

5.org.apache.fop.apps.FOPException: null:1:3868 A table row must be child of fo:table-body, fo:table-header or fo:table-footer, not fo:table-row
如果列属性1和列属性2名称相同,就会抛出上面的异常。
<@ec.row>
  <@ec.column property="属性1" />
  <@ec.column property="属性2" />
</@ec.row>

即上面的添加,修改,删除的property="null"都一样的会抛出异常。

 

6.控制添加,修改,删除这三个列不导出。viewsDenied="pdf,xls",在导出pdf,xls的时候。

默认允许viewsAllowed="pdf,xls"

 

7.导出excel,pdf功能要求在web.xml文件中:

<!-- ec Table -->
    <context-param>
         <param-name>extremecomponentsPreferencesLocation</param-name>
         <param-value>/conf/extremetable.properties</param-value>
    </context-param> 
    <filter>
       	<filter-name>eXtremeExport</filter-name>
       	<filter-class>org.extremecomponents.table.filter.ExportFilter
    	</filter-class>    
    </filter>

 以上代码放在web.xml文件的最上面。

 (详见:主题:关于extremeTable导出Excel的问题(已解决)  http://www.iteye.com/topic/107817

 

 8.extremecomponents Filter过滤时中文乱码解决方案

新建MyFilter类,实现Filter接口。

package com.studio502.util;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class MyFilter implements Filter {

	protected String encoding = null;

	protected FilterConfig filterConfig = null;

	protected boolean ignore = true;

	public void destroy() {
		this.encoding = null;
		this.filterConfig = null;
	}

	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		// Conditionally select and set the character encoding to be used
		if (ignore || (request.getCharacterEncoding() == null)) {
			String encoding = selectEncoding(request);
			if (encoding != null) {
				request.setCharacterEncoding(encoding);
				System.out.println("encoding:" + encoding);
			}
		}
		// Pass control on to the next filter
		chain.doFilter(request, response);
	}

	public void init(FilterConfig filterConfig) throws ServletException {
		this.filterConfig = filterConfig;
		this.encoding = filterConfig.getInitParameter("encoding");
		String value = filterConfig.getInitParameter("ignore");
		if (value == null)
			this.ignore = true;
		else if (value.equalsIgnoreCase("true"))
			this.ignore = true;
		else if (value.equalsIgnoreCase("yes"))
			this.ignore = true;
		else
			this.ignore = false;
	}

	protected String selectEncoding(ServletRequest request) {
		return (this.encoding);
	}

}

 在web.xml中添加以下代码加载:

<filter>
	    <filter-name>charset</filter-name>
	    <filter-class>com.studio502.util.MyFilter</filter-class>
	    <init-param>
	      <param-name>encoding</param-name>
	      <param-value>UTF-8</param-value>
	    </init-param>
	</filter>
	<filter-mapping>
	    <filter-name>charset</filter-name>
	    <url-pattern>/*</url-pattern>
	</filter-mapping>

 就完成了,另外说明的是:以上过滤器将servlet中转码问题也解决了,以下代码就可以注释了。
title = new String(title.getBytes("ISO-8859-1"),"UTF-8");

 

你可能感兴趣的:(component)