幸せのちから

平凡的世界
看似平常实崎岖
成如容易却艰辛

eXtremeComponents FAQ(中文)

eXtremeComponents FAQ

eXtremeComponents FAQ(中文版)

Jeff Johnston

Lucky

冷月宫主

版本0.1.0

本文档允许在遵守以下两条原则的条件下被使用和传播: 1)不能凭借本文档索取任何费用 2)以任何方式(印刷物或电子版)使用和传播时本文档时,必须包含本版权申明

(更新中...)


eXtremeComponents FAQ(中文)


1. 如何使用导出功能

Q: 如何使用导出功能

A: 为了使用导出功能,只需要在web.xml文件中加入eXtremeComponents的导出过滤器的配置,内容如下:

<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>

2. 传入中文参数乱码

Q: 传入中文参数乱码,如下页面:

		<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"),在我的试用过程中到页面上会出现传递过去的参数,但出现了乱码问题,使用查询(filter)功能是的中文参数问题类似。

A:

  1. 确认服务器的参数是否设置了正确的编码,如果使用Tomcat请确认Server.xml:

     <Connector port="80" URIEncoding="UTF-8" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false"
    redirectPort="8443" acceptCount="100" debug="0" connectionTimeout="20000" disableUploadTimeout="true" />
  2. 添加编码过滤器到你的应用工程:

    /*
    * Copyright 1999-2001,2004 The Apache Software Foundation.
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
    *
    * http://www.apache.org/licenses/LICENSE-2.0
    *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS,
    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    * See the License for the specific language governing permissions and
    * limitations under the License.
    */


    package filters;


    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;
    import javax.servlet.UnavailableException;


    /**
    * <p>Example filter that sets the character encoding to be used in parsing the
    * incoming request, either unconditionally or only if the client did not
    * specify a character encoding. Configuration of this filter is based on
    * the following initialization parameters:</p>
    * <ul>
    * <li><strong>encoding</strong> - The character encoding to be configured
    * for this request, either conditionally or unconditionally based on
    * the <code>ignore</code> initialization parameter. This parameter
    * is required, so there is no default.</li>
    * <li><strong>ignore</strong> - If set to "true", any character encoding
    * specified by the client is ignored, and the value returned by the
    * <code>selectEncoding()</code> method is set. If set to "false,
    * <code>selectEncoding()</code> is called <strong>only</strong> if the
    * client has not already specified an encoding. By default, this
    * parameter is set to "true".</li>
    * </ul>
    *
    * <p>Although this filter can be used unchanged, it is also easy to
    * subclass it and make the <code>selectEncoding()</code> method more
    * intelligent about what encoding to choose, based on characteristics of
    * the incoming request (such as the values of the <code>Accept-Language</code>
    * and <code>User-Agent</code> headers, or a value stashed in the current
    * user's session.</p>
    *
    * @author Craig McClanahan
    * @version $Revision: 1.3 $ $Date: 2004/02/28 03:35:22 $
    */

    public class SetCharacterEncodingFilter implements Filter {


    // ----------------------------------------------------- Instance Variables


    /**
    * The default character encoding to set for requests that pass through
    * this filter.
    */
    protected String encoding = null;


    /**
    * The filter configuration object we are associated with. If this value
    * is null, this filter instance is not currently configured.
    */
    protected FilterConfig filterConfig = null;


    /**
    * Should a character encoding specified by the client be ignored?
    */
    protected boolean ignore = true;


    // --------------------------------------------------------- Public Methods


    /**
    * Take this filter out of service.
    */
    public void destroy() {

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

    }


    /**
    * Select and set (if specified) the character encoding to be used to
    * interpret request parameters for this request.
    *
    * @param request The servlet request we are processing
    * @param result The servlet response we are creating
    * @param chain The filter chain we are processing
    *
    * @exception IOException if an input/output error occurs
    * @exception ServletException if a servlet error occurs
    */
    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);
    }

    // Pass control on to the next filter
    chain.doFilter(request, response);

    }


    /**
    * Place this filter into service.
    *
    * @param filterConfig The filter configuration object
    */
    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 Methods


    /**
    * Select an appropriate character encoding to be used, based on the
    * characteristics of the current request and/or filter initialization
    * parameters. If no character encoding should be set, return
    * <code>null</code>.
    * <p>
    * The default implementation unconditionally returns the value configured
    * by the <strong>encoding</strong> initialization parameter for this
    * filter.
    *
    * @param request The servlet request we are processing
    */
    protected String selectEncoding(ServletRequest request) {

    return (this.encoding);

    }


    }
  3. 在web.xml中添加编码过滤器配置:

     <filter>
    <filter-name>Set Character Encoding</filter-name>
    <filter-class>filters.SetCharacterEncodingFilter</filter-class>
    <init-param>
    <param-name>encoding</param-name>
    <param-value>gb2312</param-value>
    </init-param>
    </filter>
    <filter-mapping>
    <filter-name>Set Character Encoding</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>

3. 导出时中文文件名乱码

Q:关于导出时中文文件名为乱码的问题

A: 这是个bug,建议使用英文文件名,主要原因还是编码问题。我们现在正在想办法解决。

4. 导出时文件内容乱码

Q:导出时文件内容乱码

A:首先请确认使用的是extremecomponents-1.0.1-M5-A4版以后的版本

  1. Excle: 导出为Excle的中文问题已经修正,默认的情况下支持导出中文,用户不需要任何改动
  2. PDF : 由于extremecomponents使用了FOP来生成PDF文件,FOP在导出中文内容时会产生乱码。具体的解决方案 大家可以参考最新eXtremeComponents包:支持 PDF中文导出

5. 变量命名问题

Q:当变量名为"action",在IE下执行产生javascript错误

A: 内部使用了一些关键字,就目前我所知的为"action"、"submit"。建议大家命名时尽量避免,如果大家必须使用,则可以使用table标签的autoIncludeParameters参数设置为"false":

autoIncludeParameters="false"

6. 格式化输出表单中的数据

Q:怎么样格式化输出表单中的数据

A: 你可以设置列的cell:

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

详细信息请参考指南

7. 加入链接

Q:怎么样加入链接

A: 你可以参考下例:

            <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>

8. 行高亮显示

Q: 我想使用行的高亮显示如何设置

A: 你只需要设置行标签的highlightRow属性: highlightRow="true"。eXtremeComponents提供了很多接口允许用户按照自己的习惯来进行定制,包括:CSS、CELL、View。相关信息请参考指南。

posted on 2006-03-31 15:07 Lucky 阅读(11089) 评论(14)  编辑  收藏 所属分类: extremeComponents

评论

# re: eXtremeComponents FAQ(中文) 2006-03-31 18:34 keith

冷月宫主 是谁?好熟悉啊!  回复  更多评论   

# re: eXtremeComponents FAQ(中文) 2006-03-31 18:55 Lucky

我旁边的技术链接有链接,你可以去他网站看看,资料挺多的。  回复  更多评论   

# re: eXtremeComponents FAQ(中文) 2006-04-01 12:51 差沙

关于导出时中文文件名为乱码的问题

还是因为那个编码过滤器的问题。  回复  更多评论   

# re: eXtremeComponents FAQ(中文) 2006-04-01 13:33 Lucky

@差沙
你说的很对,就是因为加的编码过滤器导致乱码。  回复  更多评论   

# re: eXtremeComponents FAQ(中文) 2006-04-03 12:06 冷月宫主

我又经过测试,确实是加过滤器引起的,但还没有找到解决的办法。  回复  更多评论   

# re: eXtremeComponents FAQ(中文) 2006-04-03 12:16 xplucky

是啊,我现在正在想该怎么处理?我最近比较忙,没有太多时间花在这上面。大家多想想、讨论讨论。  回复  更多评论   

# re: eXtremeComponents FAQ(中文) 2006-04-07 17:19 seno

导出时中文文件名为乱码的问题的解决见http://www.springside.org.cn/docs/reference/ExtremeTable.htm  回复  更多评论   

# re: eXtremeComponents FAQ(中文) 2006-04-07 19:38 Lucky

@seno
你提到的SpringSide的这个文件名乱码方案,的确很强,我以前也实现了一个类似的。用这个同时会有一个问题,就是假如原来的文件名就是UTF-8? 我现在就碰到这样的情况。现在问题的关键: 我如何得到一个字符串使用的编码(gb2312、ISO、UTF-8),不知道哪位知道?  回复  更多评论   

# re: eXtremeComponents FAQ(中文) 2007-04-06 15:29 曾志香

你好,在freemarker下如何引用eXtremeComponents的标签库?也就像在jsp下可以引用,为何在freemarker不可以吗?如有好的例子,能否给大家展示一下!~谢谢 !
email:axiang_2898@126.com  回复  更多评论   

# re: eXtremeComponents FAQ(中文) 2007-06-01 15:40 sweetleaf

我在appfuse中,试着使用eXtremeComponents的标签库,test.jsp页面能正常显示,但是加入<ec:exportXls
fileName="dd.xls"
tooltip="Export Excel"
text="XLS"
/>后,点击导出xls的图标,页面跳转到一个空页面,名称也为test.jsp,无任何内容显示,请问,这是怎么回事?
  回复  更多评论   

# re: eXtremeComponents FAQ(中文) 2007-06-29 18:47 peterwillcn

加入的过滤器 好像和导出文件的过滤器 冲突...  回复  更多评论   

# re: eXtremeComponents FAQ(中文) 2007-08-29 16:33 乖乖兔

请问eXtremeComponents的过滤功能,即查询为什么不支持中文呢?查询时文本框是乱码.有什么办法可以解决? 感觉东西好了,但是教程方面说的还是不详细..不知道怎么样扩展及修改filter...另外Ecide这个东西,我也下载过,虽然弥补了缺憾,但是画面我不喜欢,很花俏..没有eXtremeComponents好  回复  更多评论   

# re: eXtremeComponents FAQ(中文) 2007-08-30 14:20 邓名刚

请问一下,我使用extremeTable,并且在action中使用limit来分页,但是有些jsp页面,我没有用到<ec:table>的标签, 而是自己用循环生成表格,所以我想自己写分页标签以便使用在action中已经提供好的limit功能.不知这个分页标签该如何做?
还望各位赐教!
谢谢!
  回复  更多评论   

# re: eXtremeComponents FAQ(中文) 2007-11-27 00:12 专注java开源

http://www.agilesource.org
这里有很多例子  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航:
 
<2006年3月>
2627281234
567891011
12131415161718
19202122232425
2627282930311
2345678

导航

随笔分类(125)

文章分类(5)

日本語

搜索

积分与排名

最新随笔

最新评论