风人园

弱水三千,只取一瓢,便能解渴;佛法无边,奉行一法,便能得益。
随笔 - 99, 文章 - 181, 评论 - 56, 引用 - 0
数据加载中……

eXtremeTable在开发过程中遇到的问题及解决办法

一、eXtremeTable导出乱码的问题

请下载最新的eXtremeComponents-1.0.1-M4(http://extremecomponents.org/extremesite/public/download/extremecomponents-1.0.1-M5-

A4.zip(注:我下时还是M4今天变成M5了,开发人员真勤快呀)),这个问题lucky(http://www.blogjava.net/lucky/)解决,在包中加了过滤器

,只需要在web.xml文件中加入以下内容即可:
  <filter>
    <filter-name>eXtremeExport</filter-name>
    <filter-class>org.extremecomponents.table.filter.ExportFilter</filter-class>
    <init-param>
      <param-name>responseHeadersSetBeforeDoFilter</param-name>
      <param-value>true</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>eXtremeExport</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
注:首先确认一点你的包中是否有org.extremecomponents.table.filter.ExportFilter。如果没有则下载最新的版本。

二、传递中文参数出现乱码的问题

如你的查询参数页面,如下表示:

<form id="form1" name="form1" method="post" action="应用eXtremeTable的action或是结果页面名">
  <select name="selecttype" size="6">
    <option value="第一个">第一个</option>
    <option value="第二个">第二个</option>
    <option value="第三个">第三个</option>
  </select>
  <input type="text" name="username" />
  <input type="submit" name="Submit" value="提交" />
</form>

当你提交时含有eXtremeTable的结果页面会自动取得页面上的表单参数,那怕是经过了action的mapping.findForward("forward"),在我的试用

过程中到页面上会出现传递过去的参数,但出现了乱码问题,因此向lucky请教,给出了如下解决方法,同样使用的过滤器,在这里要要提醒大

家一点,如果你在程序中使用了大量的new String(tmpArr[i].getBytes("ISO-8859-1"), "GBK"),可能会影响你的程序,你可以做这测试再用

,或是修改你的代码。

首先编写字符过滤类(SetCharacterEncodingFilter.java):

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 SetCharacterEncodingFilter implements Filter {
    public void destroy() {

        this.encoding = null;
        this.filterConfig = null;

    }

    public void doFilter(ServletRequest request, ServletResponse response,
                         FilterChain chain)
    throws IOException, ServletException {
        if (ignore || (request.getCharacterEncoding() == null)) {
            String encoding = selectEncoding(request);
            if (encoding != null)
                request.setCharacterEncoding(encoding);
        }
        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>Set Character Encoding</filter-name>
    <filter-class>com.eXtremeTable.filters.SetCharacterEncodingFilter</filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>GBK</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>Set Character Encoding</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

这里注意一点,我这里用了GBK,如果你要用GB2312也可以,如果支持国际化,你可以改为UTF-8,但目前在我的测试环境中无法解决中文问题。

四、在过滤(即查找)时出现乱码(eXtremeTable使用过滤时的中文问题)

解决方法同上

五、关于导出时中文文件名为乱码的问题(在tomcat5.5下出现这种乱码状况,在中文weblogic9.1下正常)

待解决。(注:如果不加上面的过滤器则不会出现乱码)

六、关于参数在eXtremeTable中传递的一点理解

查询参数页面-->action-->结果页面(自动取得参数不用人工干预)-->当过滤(查找)导出或排序时再次进入action-->action取得参数-->做相

应的数据处理-->返回结果页面。(经lucky(此开源组织成员)确认)

七、关于导出PDF的中文支持问题(Lucky)

    1)注册字体: 选择自己想要使用的字体(例如: 宋体),使用fop的TTFReader转换。
       大家可以参照FOP:font 进行,也可以自己在网上找一下相关的参照;
   2) 编辑字体的配置文件: userconfig.xml
       增加要使用字体的声明
       并将它放在工程的目录中比如:org.extremesite.resource.userconfig.xml
  3) 在对应的extremeComponents的配置文件(extremesite的配置文件:extremecomponents.properties)中增加

exportPdf.userconfigLocation和 exportPdf.font:
exportPdf.userconfigLocation=/org/extremesite/resource/userconfig.xml
exportPdf.font=arialuni
   4)在相应的JSP页面,增加PDF的标签

网友zjcfan的解决办法(这种方法会修改到源程序,大家看看有没有更好的解决办法):
如果的eXtremeTable导出的PDF中的中文都是#符号的话,那你要需要进行以下的一些步骤:
1.生成字体规格文件

java -cp fop.jar org.apache.fop.fonts.apps.TTFReader c:\windows\fonts\simkai.ttf simkai.xml

java -cp fop.jar org.apache.fop.fonts.apps.TTFReader -ttcname "SimSun" c:\windows\fonts\simsun.ttc simsun.xml
如果你的系统装在WINNT下,则将上面的windows换掉.

2.配置userconfig.xml

这个文件在fop.jar包的conf文件夹里,需要加入以下font

<font metrics-file="E:/eXtremeTable/font/simsun.xml" kerning="yes" embed-file="c:/windows/fonts/simsun.ttc">
 <font-triplet name="xtsimsun" style="normal" weight="normal"/>
</font>
<font metrics-file="E:/eXtremeTable/font/simkai.xml" kerning="yes" embed-file="c:/windows/fonts/simkai.ttf">
 <font-triplet name="xtsimkai" style="normal" weight="normal"/>
</font>

这里用到的simsun.xml和simkai.xml就是第一步生成的(这里必须指定本地路径E:/eXtremeTable/font/,如果能改为WEB环境里的路径就好了,我

试了一下,好像不行,有谁会呀,教我!)

3.修改org.extremecomponents.table.view.PdfView.

修改里面出现的<fo:block>标签的font-family属性,设为上面的xtsimkai.

4.修改org.extremecomponents.table.filter.ExportFilter.

在driver.run()前加几条语句,加载刚才我们配置的那个userconfig.xml文件.

ClassLoader loader = Thread.currentThread().getContextClassLoader();
InputStream is = loader.getResourceAsStream("conf/userconfig.xml");
Options options = new Options(is);

在这里Options的实例是没有使用的,仅使用它的构造函数加载了配置文件,通过以上步骤导出的PDF文件就可以正常的看见中文,其它的东方字体

也同样可以正常显示.

 

(注:相关的FOP字体大家可以参考下面IBM developerWorksd两篇文献:

如何在程序中嵌入FOP(http://www-128.ibm.com/developerworks/cn/xml/x-fop/index.html

在 Web 应用程序中动态生成国际化的 PDF(http://www-128.ibm.com/developerworks/cn/xml/x-ospdf/))

 

八、关于变量使用和表单命名的问题

在表单或是变量命名时不要使用action做为表单名或是变量名。(暂只知action如果有其它大家可以补上)


九、怎么样格式化输出表单中的数据?

日期格式化: cell = " date " format = " yyyy-MM-dd "
数字格式化: cell="currency" format="###,###,##0.00"

十、怎么样加入链接?

示例:
  <ec:table
    var="pres"
    items="presidents"
    action="${pageContext.request.contextPath}/compact.run"
    imagePath="${pageContext.request.contextPath}/images/table/compact/*.gif"
    view="compact"
    title="Compact Toolbar View"
    showTooltips="false"
    >
      <ec:exportPdf
           fileName="output.pdf"
           tooltip="Export PDF"
           headerColor="black"
           headerBackgroundColor="#b6c2da"
           headerTitle="Presidents"
           text="PDF"
           />
      <ec:exportXls
           fileName="output.xls"
           tooltip="Export Excel"
           text="XLS"
           />
        <ec:row>
            <ec:column property="fullName" title="Name">
               <a href="http://www.whitehouse.gov/history/presidents/">${pres.fullName}</a>
            </ec:column>
            <ec:column property="nickName"/>
            <ec:column property="term"/>
            <ec:column property="born" cell="date"/>
            <ec:column property="died" cell="date"/>
            <ec:column property="career"/>
        </ec:row>
  </ec:table>

十一、加入<tr class="odd"  onmouseover="this.className='highlight'"  onmouseout="this.className='odd'" >特性

在<ec:row>中加入highlightRow="true"属性,可以修改CSS文件自定义。

使用示例:
<ec:table items="mytable" action="${pageContext.request.contextPath}/eXtremeDemo.jsp"

imagePath="${pageContext.request.contextPath}/images/zh_CN/*.gif" cellpadding="1" title="my bread" locale="zh_CN">
  <ec:exportXls fileName="中文.xls" tooltip="导出为电子表格文件" text="XLS"/>
  <ec:exportCsv fileName="中文.csv" tooltip="导出为CSV文件" text="CSV"/>
  <ec:exportPdf fileName="中文.pdf" tooltip="导出为PDF文件" text="PDF"/>
  <ec:row>
    <ec:column property="code"/>
    <ec:column property="name"/>
    <ec:column property="status"/>
    <ec:column property="born" cell="date" format="yyyy-MM-dd"/>
  </ec:row>
</ec:table>

 

附:关于eXtremeTable使用,我也是刚刚接触,非常感谢lucky的热心帮助。再次表示感谢!


关于这个示例大家可以去http://www.seg-gps.com:8080/bak/eXtremeTableAJAXDemo.rar下载。开发环境JB+Struts+tomcat5.5.
注意:下载时必须用工具下载,不能用IE直接打开下载。


http://www.seg-gps.com:8080/bak/eXtremeComponents参考文档.doc

CHM版得正式版出后再制作。


相关贴子链接:

eXtremeComponent在中文环境下的使用

http://www.hibernate.org.cn/viewtopic.php?t=17938

演示示例:

http://www.extremecomponents.org/extremesite/public/demo/examples.jsp

eXtremeComponents参考文档(中文)

http://www.blogjava.net/lucky/articles/33380.html

学习eXtremeTable的初步好文章

http://www.blogjava.net/davidxu/archive/2005/08/09/9683.aspx

posted on 2006-07-06 17:11 风人园 阅读(2841) 评论(0)  编辑  收藏 所属分类: Java