風(fēng)人園

          弱水三千,只取一瓢,便能解渴;佛法無邊,奉行一法,便能得益。
          隨筆 - 99, 文章 - 181, 評論 - 56, 引用 - 0
          數(shù)據(jù)加載中……

          eXtremeTable在開發(fā)過程中遇到的問題及解決辦法

          一、eXtremeTable導(dǎo)出亂碼的問題

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

          A4.zip(注:我下時(shí)還是M4今天變成M5了,開發(fā)人員真勤快呀)),這個(gè)問題lucky(http://www.aygfsteel.com/lucky/)解決,在包中加了過濾器

          ,只需要在web.xml文件中加入以下內(nèi)容即可:
          ? <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>
          注:首先確認(rèn)一點(diǎn)你的包中是否有org.extremecomponents.table.filter.ExportFilter。如果沒有則下載最新的版本。

          二、傳遞中文參數(shù)出現(xiàn)亂碼的問題

          如你的查詢參數(shù)頁面,如下表示:

          <form id="form1" name="form1" method="post" action="應(yīng)用eXtremeTable的action或是結(jié)果頁面名">
          ? <select name="selecttype" size="6">
          ??? <option value="第一個(gè)">第一個(gè)</option>
          ??? <option value="第二個(gè)">第二個(gè)</option>
          ??? <option value="第三個(gè)">第三個(gè)</option>
          ? </select>
          ? <input type="text" name="username" />
          ? <input type="submit" name="Submit" value="提交" />
          </form>

          當(dāng)你提交時(shí)含有eXtremeTable的結(jié)果頁面會自動取得頁面上的表單參數(shù),那怕是經(jīng)過了action的mapping.findForward("forward"),在我的試用

          過程中到頁面上會出現(xiàn)傳遞過去的參數(shù),但出現(xiàn)了亂碼問題,因此向lucky請教,給出了如下解決方法,同樣使用的過濾器,在這里要要提醒大

          家一點(diǎn),如果你在程序中使用了大量的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>

          這里注意一點(diǎn),我這里用了GBK,如果你要用GB2312也可以,如果支持國際化,你可以改為UTF-8,但目前在我的測試環(huán)境中無法解決中文問題。

          四、在過濾(即查找)時(shí)出現(xiàn)亂碼(eXtremeTable使用過濾時(shí)的中文問題)

          解決方法同上

          五、關(guān)于導(dǎo)出時(shí)中文文件名為亂碼的問題(在tomcat5.5下出現(xiàn)這種亂碼狀況,在中文weblogic9.1下正常)

          待解決。(注:如果不加上面的過濾器則不會出現(xiàn)亂碼)

          六、關(guān)于參數(shù)在eXtremeTable中傳遞的一點(diǎn)理解

          查詢參數(shù)頁面-->action-->結(jié)果頁面(自動取得參數(shù)不用人工干預(yù))-->當(dāng)過濾(查找)導(dǎo)出或排序時(shí)再次進(jìn)入action-->action取得參數(shù)-->做相

          應(yīng)的數(shù)據(jù)處理-->返回結(jié)果頁面。(經(jīng)lucky(此開源組織成員)確認(rèn))

          七、關(guān)于導(dǎo)出PDF的中文支持問題(Lucky)

          ??? 1)注冊字體: 選擇自己想要使用的字體(例如: 宋體),使用fop的TTFReader轉(zhuǎn)換。
          ?????? 大家可以參照FOP:font 進(jìn)行,也可以自己在網(wǎng)上找一下相關(guān)的參照;
          ?? 2) 編輯字體的配置文件: userconfig.xml
          ?????? 增加要使用字體的聲明
          ?????? 并將它放在工程的目錄中比如:org.extremesite.resource.userconfig.xml
          ? 3) 在對應(yīng)的extremeComponents的配置文件(extremesite的配置文件:extremecomponents.properties)中增加

          exportPdf.userconfigLocation和 exportPdf.font:
          exportPdf.userconfigLocation=/org/extremesite/resource/userconfig.xml
          exportPdf.font=arialuni
          ?? 4)在相應(yīng)的JSP頁面,增加PDF的標(biāo)簽

          網(wǎng)友zjcfan的解決辦法(這種方法會修改到源程序,大家看看有沒有更好的解決辦法):
          如果的eXtremeTable導(dǎo)出的PDF中的中文都是#符號的話,那你要需要進(jìn)行以下的一些步驟:
          1.生成字體規(guī)格文件

          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
          如果你的系統(tǒng)裝在WINNT下,則將上面的windows換掉.

          2.配置userconfig.xml

          這個(gè)文件在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環(huán)境里的路徑就好了,我

          試了一下,好像不行,有誰會呀,教我!)

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

          修改里面出現(xiàn)的<fo:block>標(biāo)簽的font-family屬性,設(shè)為上面的xtsimkai.

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

          在driver.run()前加幾條語句,加載剛才我們配置的那個(gè)userconfig.xml文件.

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

          在這里Options的實(shí)例是沒有使用的,僅使用它的構(gòu)造函數(shù)加載了配置文件,通過以上步驟導(dǎo)出的PDF文件就可以正常的看見中文,其它的東方字體

          也同樣可以正常顯示.

          ?

          (注:相關(guān)的FOP字體大家可以參考下面IBM developerWorksd兩篇文獻(xiàn):

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

          在 Web 應(yīng)用程序中動態(tài)生成國際化的 PDF(http://www-128.ibm.com/developerworks/cn/xml/x-ospdf/))

          ?

          八、關(guān)于變量使用和表單命名的問題

          在表單或是變量命名時(shí)不要使用action做為表單名或是變量名。(暫只知action如果有其它大家可以補(bǔ)上)


          九、怎么樣格式化輸出表單中的數(shù)據(jù)?

          日期格式化: cell = " date " format = " yyyy-MM-dd "
          數(shù)字格式化: 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=">
          ??????????? </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="導(dǎo)出為電子表格文件" text="XLS"/>
          ? <ec:exportCsv fileName="中文.csv" tooltip="導(dǎo)出為CSV文件" text="CSV"/>
          ? <ec:exportPdf fileName="中文.pdf" tooltip="導(dǎo)出為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>

          ?

          附:關(guān)于eXtremeTable使用,我也是剛剛接觸,非常感謝lucky的熱心幫助。再次表示感謝!


          關(guān)于這個(gè)示例大家可以去
          http://www.seg-gps.com:8080/bak/eXtremeTableAJAXDemo.rar下載。開發(fā)環(huán)境JB+Struts+tomcat5.5.
          注意:下載時(shí)必須用工具下載,不能用IE直接打開下載。


          http://www.seg-gps.com:8080/bak/eXtremeComponents參考文檔.doc

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


          相關(guān)貼子鏈接:

          eXtremeComponent在中文環(huán)境下的使用

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

          演示示例:

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

          eXtremeComponents參考文檔(中文)

          http://www.aygfsteel.com/lucky/articles/33380.html

          學(xué)習(xí)eXtremeTable的初步好文章

          http://www.aygfsteel.com/davidxu/archive/2005/08/09/9683.aspx

          posted on 2006-07-06 17:11 風(fēng)人園 閱讀(2850) 評論(0)  編輯  收藏 所屬分類: Java

          主站蜘蛛池模板: 长垣县| 沙洋县| 彰武县| 鸡西市| 礼泉县| 海口市| 淳化县| 富川| 青铜峡市| 房产| 吴江市| 烟台市| 托克托县| 唐山市| 泾川县| 荣昌县| 义马市| 嘉兴市| 连山| 望城县| 横峰县| 视频| 阳山县| 喀喇沁旗| 雅江县| 洮南市| 封开县| 海晏县| 威信县| 称多县| 大兴区| 屏南县| 会同县| 新营市| 汨罗市| 无棣县| 寿光市| 舞钢市| 信丰县| 二连浩特市| 肥西县|