[ECSide] 【总结】◆◆◆◆ECSide2.0RC1目前发现的问题!◆◆◆◆(请看最后回复帖,更新至2007-10-28 某些环境下使用#_EX报错的解决方法~)
pharaohsprince
2007-09-19
偶用了ECSide2.0RC1时间不长·的确有很多亮点~但是,目前只是停留在测试研究阶段~
主要原因,在Weblogic8.1环境下,很多BUG就出来了~浏览下论坛,发现和我遇到一样问题的人还不少哦 ------------------------------------- 总结如下(Weblogic8.1.6,JDK1.4环境): ------------------------------------- 1.AJAX方式刷新,分页,排序后,出现乱码???。 (目前通过修改 ECSide.js 文件里 113行 Me.findAjaxZoneAtClient=true 暂时解决) 2.导出XSL,CSV等文件的时候,出现空白无数据。(已经解决) 详情:http://ecside.group.iteye.com/group/topic/3002 3.<ec:column 标签内的 mappingItem 属性 页面加载的时候无效果,依旧显示代码!不会出现对应的文字。(已解决...) 原版: Object result = getColumnValue(); if (result == null && mappingItem!=null && propertyValue!=null ) 搞不懂为什么要result==null??应该是FINS手误吧,去掉就正常了!! if (mappingItem!=null && propertyValue!=null ){ 详情:http://ecside.group.iteye.com/group/blog/129921 同时支持mappingItem的key与value都为Integer类型时也没有问题! 4.使用demo_action.jsp,在使用Struts的Action作为反馈地址的时候,参数必须使用actionMethod: 例如:/demo.do?actionMethod=doQuery 如果换成 /demo.do?action=doQuery ,在分页,刷新等页面重加载的时候就会脚本报错~~~(2007-09-19日最新发现,待解决...) wldandan 写道 请问一下大家,
在显示列表的时候,每一行应该有"修改"、"删除"的操作吧 你们是怎么实现的? 我现在是这样,增加2列作为修改、删除的列,然后加入<a href>,提供修改、删除的链接: <ec:row> <ec:column width="15%" property="username" title="角色" /> <ec:column width="10%" property="password" title="密码" /> <ec:column width="20%" property="firstName" title="电子信箱" /> <ec:column width="10%" property="lastName" title="性别" /> <ec:column width="15%" property="dateCreated" title="注册时间" /> <ec:column width="10%" property="assetsValue" title="修改" viewsDenied="xls" > <a href="${pageContext.request.contextPath}/user/Edit.action?id=${pageScope.record.id}">修改</a> </ec:column> <ec:column width="10%" property="assetsValue" title="删除" viewsDenied="cvs"> <a href="#" onclick="confirm('您确定要删除?');">删除</a> </ec:column> </ec:row> 但是导出Excel的时候,会将"修改"、"删除"也导出,设置了viewsDenied="cvs"后, 只是列标题被隐藏了,内容也还是被导出,请问大家有没有好的建议??! 希望,ECSide2.0最终正式版推出前能多多考虑使用不同服务器的兼容问题! 希望,ECSide2.0最终正式版推出的时候能解决这些问题~~~ 如果,以上问题已经有兄弟解决·请赐教~谢谢···· |
|
pharaohsprince
2007-09-19
导出EXCEL为空
xiaotiaotiao 写道 解决了
在1.3版本里对比看了下 发现XlsView里面的用到的outputstream 改为1.3版本的ByteArrayOutputStream 同时在beforeBody里改为outputStream=new ByteArrayOutputStream 注释掉原来的 outputStream = ContextUtils.getResponseOutputStream(model.getContext); 在afterbody方法的最后finally注释掉outputStream=null; 就可以了 不过还不知道fins的2.0的目的是什么,我这样改了的话会不会引出问题等等,现在先这样改了 |
|
pharaohsprince
2007-09-19
2.0总感觉是半成品·,还是 1.3final用的比较稳定·
|
|
pharaohsprince
2007-09-19
尽量不用预读功能~
dionwang 写道 是设置<ec:table>中的doPreload="false"
|
|
zyzdy
2007-09-20
在页面上排序无效,目前翻页速度很慢,而且翻到第83页后,会将83页到163页作为一页显示出来用户要等待50多秒。
|
|
pharaohsprince
2007-09-21
大数据量查询,还是不要用全部取出的方式·用数据库层的分页查询,DEMO_ACTION.JSP里对应的 ACTION.JAVA文件里有实现分页的2种方式·可以研究以下·
|
|
pn2006
2007-09-22
Excel导出为空。
按照xiaotiaotiao的方法试了好像不行啊 |
|
pharaohsprince
2007-09-24
pn2006 写道 Excel导出为空。
按照xiaotiaotiao的方法试了好像不行啊 经过我的测试·已经搞定了CSV的文件导出~没问题· XLS可能是内部编码问题··正在解决中...... 下次再把代码给帖出来··· |
|
pharaohsprince
2007-09-24
【完美解决ecside2.0RC1在weblogic8.1.6环境下导出xls,csv 文件为空的情况】~法老修正完整版!
http://ecside.group.iteye.com/group/topic_quote/18035 |
|
pharaohsprince
2007-09-26
【完美解决ecside2.0RC1在weblogic8.1.6环境下导出xls,csv 文件为空的情况】~法老修正完整版!
pharaohsprince 写道 pharaohsprince 写道 今天是中秋节哟~~
-------------------------------------------- 这2天一直在努力解决ecside2.0RC1在weblogic8.1.6环境下导出xls,csv 文件为空的情况~ 期间 xiaotiaotiao 的一篇帖子给我不少灵感~ ------------------------------------- 在1.3版本里对比看了下 发现XlsView里面的用到的outputstream 改为1.3版本的ByteArrayOutputStream 同时在beforeBody里改为outputStream=new ByteArrayOutputStream ----------------------------------------------------------- 于是我就尝试改了一下csvView.java结果成功了~开心了半天~ 但是,用同样方法的处理xlsView.java却一直不成功,继续郁闷...... 今天,我干脆从头到尾把csvView,xlsView做了一下比较和研究~发现xlsView是比csvView缩水处理了~~呵呵 注意原版xlsView和csvView在以下片段不同~ private ByteArrayOutputStream outputStream ; private ByteArrayOutputStream outputStreamOut; private PrintWriter out =null; csvView 是定义了以上3个供输出的属性~而xlsView只有 outputStream 这一个!! 今天偶然又看了一下XlsViewResolver.java文件。。发现问题了~~~居然里面的代码给注释掉了... 这时候我在看xlsView的afterBody方法 发现直接返回outputStream对象~~ ******************************************************** 可能fins的本来的想法是直接把xls流提交给IE浏览器,让它自己解析出XLS文件下载~ 没有使用PrintWriter方法输出!!事实证明TOMCAT5.5是可以的,WEBLOGIC就不可以~ ******************************************************** 好了,问题找到了·解决起来就快了~~~~ 参考CsvView,CsvViewResolver对XlsView,XlsViewResolver做了修改 总结如下(Weblogic8.1.6,JDK1.4环境;TOMCAT 5.5 JDK1.6环境全部通过): XlsView.java 写道 /* Copyright 2006-2007 original author or authors. * * 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 org.ecside.view; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import jxl.Cell; import jxl.Workbook; import jxl.format.Border; import jxl.format.BorderLineStyle; import jxl.format.CellFormat; import jxl.format.Colour; import jxl.write.Blank; import jxl.write.Label; import jxl.write.Number; import jxl.write.NumberFormat; import jxl.write.WritableCellFormat; import jxl.write.WritableFont; import jxl.write.WritableSheet; import jxl.write.WritableWorkbook; import jxl.write.WriteException; import jxl.write.biff.RowsExceededException; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.ecside.common.log.LogHandler; import org.ecside.core.ECSideContext; import org.ecside.core.TableModel; import org.ecside.core.bean.Column; import org.ecside.preferences.PreferencesConstants; import org.ecside.table.calc.CalcResult; import org.ecside.table.calc.CalcUtils; import org.ecside.util.ECSideUtils; import org.ecside.util.ExportViewUtils; import org.ecside.util.ExtremeUtils; import org.htmlparser.Node; import org.htmlparser.NodeFilter; import org.htmlparser.Parser; import org.htmlparser.nodes.TagNode; import org.htmlparser.tags.TableColumn; import org.htmlparser.tags.TableRow; import org.htmlparser.tags.TableTag; import org.htmlparser.util.NodeList; /** * @author Wei Zijun * @editor by pharaohsprince 法老 * http://blog.csdn.net/pharaohsprince * 2007.09.25 中秋节 */ /** * com.extremecomp.table.view.XlsView.java - * * @author paul horn */ public class XlsView implements View { private Log logger = LogFactory.getLog(XlsView.class); public static final int WIDTH_MULT = 240; // width per char public static final int MIN_CHARS = 8; // minimum char width public static final short DEFAULT_FONT_HEIGHT = 8; public static final double NON_NUMERIC = -.99999; public static final String DEFAULT_MONEY_FORMAT = "$###,###,##0.00"; public static final String DEFAULT_PERCENT_FORMAT = "##0.0%"; public static final String NBSP = " "; public static final int colWidth=15; private WritableWorkbook wb; private WritableSheet sheet; private int rownum; private short cellnum; private String moneyFormat; private String percentFormat; private ByteArrayOutputStream outputStream ; private ByteArrayOutputStream outputStreamOut; private PrintWriter out =null; private String encoding; public XlsView() { encoding=ECSideContext.ENCODING; } public void beforeBody(TableModel model) { logger.debug("XlsView.init()"); outputStream=new ByteArrayOutputStream(); outputStreamOut=outputStream; out=new PrintWriter(outputStream); moneyFormat = model.getPreferences().getPreference(PreferencesConstants.TABLE_EXPORTABLE + "format.money"); if (StringUtils.isEmpty(moneyFormat)) { moneyFormat = DEFAULT_MONEY_FORMAT; } percentFormat = model.getPreferences().getPreference(PreferencesConstants.TABLE_EXPORTABLE + "format.percent"); if (StringUtils.isEmpty(percentFormat)) { percentFormat = DEFAULT_PERCENT_FORMAT; } // encoding = model.getExportHandler().getCurrentExport().getEncoding(); try { wb = Workbook.createWorkbook(outputStream); sheet = wb.createSheet("Export Workbook",0); createHeader(model); // int totalCol=model.getColumnHandler().getColumns().size(); rownum++; String extendRowBefore=(String)(model.getTable().getAttribute("ExtendRowBefore")); rownum+=createRow(sheet, getRows(extendRowBefore,encoding),(CellFormat)WritableWorkbook.NORMAL_STYLE, rownum,0)-1; } catch (Exception e) { LogHandler.errorLog(logger, e); } } public static TableRow[] getRows(String inputHtml,String encode) throws Exception { if (StringUtils.isBlank(inputHtml)){ return null; } inputHtml=inputHtml.trim(); if (!inputHtml.startsWith("<table>")&&!inputHtml.startsWith("<TABLE>") ){ inputHtml="<table>"+inputHtml+"</table>"; } Parser parser = Parser.createParser(inputHtml, encode); NodeList nodes = parser.extractAllNodesThatMatch(new NodeFilter() { public boolean accept(Node node) { return node instanceof TagNode; } }); TagNode node = (TagNode)nodes.elementAt(0); return ((TableTag)node).getRows(); } public static int getColumnNum(TableRow row){ int totalCol=0; TableColumn[] columns=row.getColumns(); for (int cn=0;cn<columns.length;cn++){ String colspan=columns[cn].getAttribute("colspan"); if (colspan!=null&&colspan.length()>0){ try{ totalCol+=Integer.parseInt(colspan); continue; }catch(Exception e){} } totalCol++; } return totalCol; } public static int createRow(WritableSheet sheet,TableRow[] tableRows,CellFormat cellFormat,int startRow,int startCol) throws RowsExceededException, WriteException{ if (tableRows==null||tableRows.length<1) { return 0; } int totalCol=getColumnNum(tableRows[0]); // CellFormat cellFormat=(CellFormat)WritableWorkbook.NORMAL_STYLE; int colWidth=15; List mergeCells=new ArrayList(); for (int rowNo=startRow;rowNo<startRow+tableRows.length;rowNo++ ){ int idx=0; for (int colNo=startCol;colNo<startCol+totalCol;colNo++){ Cell cell=sheet.getCell(colNo,rowNo); if (cell instanceof Blank) { continue; } TableColumn tdBean=((TableRow)tableRows[rowNo-startRow]).getColumns()[idx]; String title=ECSideUtils.specialHTMLToShowTEXT(tdBean.toPlainTextString()); Label label=new Label(colNo,rowNo,title,cellFormat); sheet.addCell(label); sheet.setColumnView(colNo, colWidth); idx++; int ce=Integer.parseInt(ECSideUtils.convertString(tdBean.getAttribute("colspan"),"1"))-1; int re=Integer.parseInt(ECSideUtils.convertString(tdBean.getAttribute("rowspan"),"1"))-1; if (ce>=1 || re>=1){ ce=ce<0?0:ce; re=re<0?0:re; mergeCells.add(new int[]{colNo,rowNo,colNo+ce,rowNo+re}); if (ce<1 && re>=1){ for (int srowNo=1;srowNo<=re; srowNo++){ sheet.addCell(new Blank(colNo,rowNo+srowNo)); sheet.setColumnView(colNo, colWidth); } continue; }else if (re<1 && ce>=1){ for (int scolNo=1;scolNo<=ce;scolNo++){ sheet.addCell(new Blank(colNo+scolNo,rowNo)); sheet.setColumnView(colNo+scolNo, colWidth); } colNo+=ce; continue; }else if (ce>=1 && re>=1){ for (int scolNo=1;scolNo<=ce;scolNo++){ for (int srowNo=1;srowNo<=re; srowNo++){ sheet.addCell(new Blank(colNo+scolNo,rowNo+srowNo)); sheet.setColumnView(colNo+scolNo, colWidth); } } colNo+=ce; continue; } } } } for (int i=0;i<mergeCells.size();i++){ int[] mc=(int[])mergeCells.get(i); sheet.mergeCells(mc[0],mc[1],mc[2],mc[3]); } return tableRows.length; } private void createHeader(TableModel model) throws RowsExceededException, WriteException { rownum = 0; cellnum = 0; int etr=0; //HSSFRow row = sheet.createRow(rownum); WritableCellFormat cellFormat=new WritableCellFormat(); WritableFont arial10font = new WritableFont(WritableFont.ARIAL,WritableFont.DEFAULT_POINT_SIZE,WritableFont.BOLD); cellFormat.setBackground(Colour.GRAY_25); cellFormat.setBorder(Border.ALL, BorderLineStyle.THIN,Colour.GRAY_50); cellFormat.setFont(arial10font); boolean showHeader=model.getTable().isShowHeader(); List columns = model.getColumnHandler().getHeaderColumns(); String extendRowTop=(String)(model.getTable().getAttribute("ExtendRowTop")); try { etr=createRow(sheet, getRows(extendRowTop,encoding),cellFormat, rownum,0); } catch (Exception e) { LogHandler.warnLog(logger, e); etr=0; } rownum+=etr; if (showHeader || etr<1){ for (Iterator iter = columns.iterator(); iter.hasNext();) { Column column = (Column) iter.next(); String title = column.getCellDisplay(); Label label=new Label(cellnum,rownum,title,cellFormat); sheet.addCell(label); int valWidth = (title + "").length() ; valWidth=1; sheet.setColumnView(cellnum, valWidth*colWidth); cellnum++; } }else{ if (rownum>0){ rownum--; } } } public void body(TableModel model, Column column) { if (column.isFirstColumn()) { rownum++; cellnum = 0; } try { String value = ExportViewUtils.parseXLS(column.getCellDisplay()); if (column.isEscapeAutoFormat()) { writeToCellAsText(value, null); } else { writeToCellFormatted(value, null); } cellnum++; } catch (RowsExceededException e) { // TODO Auto-generated catch block LogHandler.errorLog(logger, e); } catch (WriteException e) { // TODO Auto-generated catch block LogHandler.errorLog(logger, e); } } public Object afterBody(TableModel model) { if (model.getLimit().getTotalRows() != 0) { try { totals(model); } catch (RowsExceededException e) { // TODO Auto-generated catch block LogHandler.errorLog(logger, e); } catch (WriteException e) { // TODO Auto-generated catch block LogHandler.errorLog(logger, e); } } try { // int totalCol=model.getColumnHandler().getColumns().size(); rownum++; String extendRowAfter=(String)(model.getTable().getAttribute("ExtendRowAfter")); rownum+=createRow(sheet, getRows(extendRowAfter,encoding),(CellFormat)WritableWorkbook.NORMAL_STYLE, rownum,0); wb.write(); wb.close(); out.flush(); out.close(); } catch (WriteException e) { LogHandler.warnLog(logger, e); } catch (IOException e) { LogHandler.warnLog(logger, e); } catch (Exception e) { LogHandler.warnLog(logger, e); } return outputStreamOut; } private void writeToCellAsText( String value, WritableCellFormat styleModifier) throws RowsExceededException, WriteException { // format text if (value.trim().equals(NBSP)) { value = ""; } Label label=new Label(cellnum,rownum,value); if (styleModifier!=null){ label.setCellFormat(styleModifier); } sheet.addCell(label); } private void writeToCellFormatted( String value, WritableCellFormat styleModifier) throws RowsExceededException, WriteException { double numeric = NON_NUMERIC; try { numeric = Double.parseDouble(value); } catch (Exception e) { numeric = NON_NUMERIC; } if (value.startsWith("$") || value.endsWith("%") || value.startsWith("($")) { boolean moneyFlag = (value.startsWith("$") || value.startsWith("($")); boolean percentFlag = value.endsWith("%"); value = StringUtils.replace(value, "$", ""); value = StringUtils.replace(value, "%", ""); value = StringUtils.replace(value, ",", ""); value = StringUtils.replace(value, "(", "-"); value = StringUtils.replace(value, ")", ""); try { numeric = Double.parseDouble(value); } catch (Exception e) { numeric = NON_NUMERIC; } if (moneyFlag) { // format money NumberFormat fivedps = new NumberFormat(moneyFormat); WritableCellFormat fivedpsFormat = new WritableCellFormat(fivedps); Number number = new Number(cellnum, rownum, numeric, fivedpsFormat); if (styleModifier!=null){ number.setCellFormat(styleModifier); } sheet.addCell(number); } else if (percentFlag) { // format percent numeric = numeric / 100; NumberFormat fivedps = new NumberFormat(percentFormat); WritableCellFormat fivedpsFormat = new WritableCellFormat(fivedps); Number number = new Number(cellnum, rownum, numeric, fivedpsFormat); if (styleModifier!=null){ number.setCellFormat(styleModifier); } sheet.addCell(number); } } else if (Math.abs(numeric - NON_NUMERIC) >= .0000001) { // numeric != NON_NUMERIC // format numeric Number number = new Number(cellnum, rownum, numeric); if (styleModifier!=null){ number.setCellFormat(styleModifier); } sheet.addCell(number); } else { // format text if (value.trim().equals(NBSP)) { value = ""; } Label label=new Label(cellnum,rownum,value); if (styleModifier!=null){ label.setCellFormat(styleModifier); } sheet.addCell(label); } } // Add to export totals public void totals(TableModel model) throws RowsExceededException, WriteException { Column firstCalcColumn = model.getColumnHandler().getFirstCalcColumn(); WritableCellFormat cellFormatTotals=new WritableCellFormat(); cellFormatTotals.setBackground(Colour.GRAY_25); cellFormatTotals.setBorder(Border.ALL, BorderLineStyle.THIN,Colour.GRAY_50); if (firstCalcColumn != null) { int rows = firstCalcColumn.getCalc().length; for (int i = 0; i < rows; i++) { rownum++; cellnum = 0; for (Iterator iter = model.getColumnHandler().getColumns().iterator(); iter.hasNext();) { Column column = (Column) iter.next(); if (column.isFirstColumn()) { String calcTitle = CalcUtils.getFirstCalcColumnTitleByPosition(model, i); if (column.isEscapeAutoFormat()) { writeToCellAsText(calcTitle, cellFormatTotals); } else { writeToCellFormatted(calcTitle, cellFormatTotals); } cellnum++; continue; } if (column.isCalculated()) { CalcResult calcResult = CalcUtils.getCalcResultsByPosition(model, column, i); java.lang.Number value = calcResult.getValue(); if (value != null){ //if (column.isEscapeAutoFormat()) { // writeToCellAsText( value.toString(), cellFormatTotals); //} else { // writeToCellFormatted( ExtremeUtils.formatNumber(column.getFormat(), value, model.getLocale()), cellFormatTotals); // } if (StringUtils.isNotBlank(column.getFormat())){ writeToCellFormatted( ExtremeUtils.formatNumber(column.getFormat(), value, model.getLocale()), cellFormatTotals); }else{ writeToCellAsText( value.toString(), cellFormatTotals); } } else { Label label=new Label(cellnum,rownum,"n/a"); sheet.addCell(label); } cellnum++; } else { writeToCellFormatted( "", cellFormatTotals); cellnum++; } } } } } } XlsViewResolver.java 写道 /* * Copyright 2006-2007 original author or authors. * * 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 org.ecside.view; import java.io.ByteArrayOutputStream; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import org.ecside.core.Preferences; /** * @author Wei Zijun * @editor by pharaohsprince 法老 * http://blog.csdn.net/pharaohsprince * 2007.09.25 中秋节 */ public class XlsViewResolver implements ViewResolver { public void resolveView(ServletRequest request, ServletResponse response, Preferences preferences, Object viewData) throws Exception { if (viewData!=null){ ByteArrayOutputStream out = (ByteArrayOutputStream)viewData; byte[] contents = out.toByteArray(); response.setContentLength(contents.length); response.getOutputStream().write(contents); } } } CsvView.java 写道 /* * Copyright 2004 original author or authors. * * 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 org.ecside.view; import java.io.ByteArrayOutputStream; import java.io.PrintWriter; import java.util.Iterator; import java.util.List; import org.apache.commons.lang.StringUtils; import org.ecside.core.TableModel; import org.ecside.core.bean.Column; import org.ecside.core.bean.Export; import org.ecside.table.calc.CalcResult; import org.ecside.table.calc.CalcUtils; import org.ecside.util.ExportViewUtils; import org.ecside.util.ExtremeUtils; /** * For producing a delimited datafile view of the table. Default delimiter is * comma. * * @author Wei Zijun * @editor by pharaohsprince 法老 * http://blog.csdn.net/pharaohsprince * 2007.09.25 中秋节 */ public class CsvView implements View { public final static String DELIMITER = "delimiter"; final static String DEFAULT_DELIMITER = ","; // private StringBuffer plainData = new StringBuffer(); private ByteArrayOutputStream outputStream ; private ByteArrayOutputStream outputStreamOut; private StringBuffer rowBuffer =null; private PrintWriter out =null; private String delimiter; public void beforeBody(TableModel model) { outputStream=new ByteArrayOutputStream(); outputStreamOut=outputStream; /* outputStream=ContextUtils.getResponseOutputStream(model.getContext()); outputStreamOut=null; if (outputStream==null){ outputStream=new ByteArrayOutputStream(); outputStreamOut=outputStream; }*/ out=new PrintWriter(outputStream); Export export = model.getExportHandler().getCurrentExport(); delimiter = export.getAttributeAsString(DELIMITER); List columns = model.getColumnHandler().getHeaderColumns(); if (StringUtils.isBlank(delimiter)) { delimiter = DEFAULT_DELIMITER; } boolean isFirstColumn=true; rowBuffer = new StringBuffer(); for (Iterator iter = columns.iterator(); iter.hasNext();) { Column column = (Column) iter.next(); String value = ExportViewUtils.parseCSV(column.getCellDisplay()); if (!isFirstColumn){ rowBuffer.append(delimiter); } rowBuffer.append(value); isFirstColumn=false; } if (columns.size()>0){ rowBuffer.append(ExportViewUtils.BR); writeToOutputStream(rowBuffer.toString()); } } public void body(TableModel model, Column column) { String value = ExportViewUtils.parseCSV(column.getCellDisplay()); rowBuffer.append(value); if (column.isLastColumn()) { rowBuffer.append(ExportViewUtils.BR); writeToOutputStream(rowBuffer.toString()); }else{ rowBuffer.append(delimiter); } } public Object afterBody(TableModel model) { totals(model); out.flush(); out.close(); return outputStreamOut; } public void totals(TableModel model) { rowBuffer = new StringBuffer(); Column firstCalcColumn = model.getColumnHandler().getFirstCalcColumn(); if (firstCalcColumn != null) { int rows = firstCalcColumn.getCalc().length; for (int i = 0; i < rows; i++) { for (Iterator iter = model.getColumnHandler().getColumns().iterator(); iter.hasNext();) { Column column = (Column) iter.next(); if (column.isFirstColumn()) { String calcTitle = CalcUtils.getFirstCalcColumnTitleByPosition(model, i); rowBuffer.append(ExportViewUtils.parseCSV(calcTitle) ); continue; } rowBuffer.append(delimiter); if (column.isCalculated()) { CalcResult calcResult = CalcUtils.getCalcResultsByPosition(model, column, i); java.lang.Number value = calcResult.getValue(); if (value != null){ if (StringUtils.isNotBlank(column.getFormat())){ rowBuffer.append(ExportViewUtils.parseCSV(ExtremeUtils.formatNumber(column.getFormat(), value, model.getLocale()))); }else{ rowBuffer.append(ExportViewUtils.parseCSV(value.toString()) ); } } else { rowBuffer.append(ExportViewUtils.parseCSV("")); } } else { rowBuffer.append(ExportViewUtils.parseCSV("")); } } rowBuffer.append(ExportViewUtils.BR); writeToOutputStream(rowBuffer.toString()); } } } public void writeToOutputStream(String rowContent){ out.print(rowContent); rowBuffer = new StringBuffer(); } } CsvViewResolver.java 写道 /* * Copyright 2004 original author or authors. * * 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 org.ecside.view; import java.io.ByteArrayOutputStream; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import org.ecside.core.Preferences; /** * @author Jeff Johnston */ /** * @editor by pharaohsprince 法老 * http://blog.csdn.net/pharaohsprince * 2007.09.25 中秋节 */ public class CsvViewResolver implements ViewResolver { public void resolveView(ServletRequest request, ServletResponse response, Preferences preferences, Object viewData) throws Exception { if (viewData!=null){ ByteArrayOutputStream out = (ByteArrayOutputStream)viewData; byte[] contents = out.toByteArray(); response.setContentLength(contents.length); response.getOutputStream().write(contents); } } } ------------------------------------------------------------------ 说明:编译ECSIDE2.0RC1的源代码,把以上文件修改后编译,把新的CLASS复制到JAR文件里覆盖对应文件即可~ |