当我点击“export as excel”链接时,我想将jsf datatable导出为excelsheet。我正在使用“Apache poi library”和“PrimeFaces”库来完成这项任务。
我使用PrimeFaces成功显示我的数据表。当我点击“export as excel”链接时,我将获得异常
javax.faces.FacesException:sheetName''无效 - 字符数 必须大于或等于1且小于或等于31.
请帮我解决问题。
谢谢。
这是我的jsf文件。
<p:dataTable id = "dataTableId" var = "pr" value = "#{dashboard.beanList}" >
<p:panel header="Export All Data">
<h:commandLink value="export as excel sheet">
<p:dataExporter type="xls" target="dataTableId" fileName="myexcel" />
</h:commandLink>
</p:panel>
这是我的stacktrace文件。
javax.faces.FacesException: sheetName '' is invalid - character count MUST be greater than or equal to 1 and less than or equal to 31
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:85)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:334)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: sheetName '' is invalid - character count MUST be greater than or equal to 1 and less than or equal to 31 at org.apache.poi.ss.util.WorkbookUtil.validateSheetName(WorkbookUtil.java:108)
at org.apache.poi.hssf.record.BoundSheetRecord.setSheetname(BoundSheetRecord.java:94)
at org.apache.poi.hssf.model.InternalWorkbook.setSheetName(InternalWorkbook.java:588)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.createSheet(HSSFWorkbook.java:798)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.createSheet(HSSFWorkbook.java:78)
at org.primefaces.component.export.ExcelExporter.export(ExcelExporter.java:52)
at org.primefaces.component.export.DataExporter.processAction(DataExporter.java:112)
at javax.faces.event.ActionEvent.processListener(ActionEvent.java:84)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:773)
at javax.faces.component.UICommand.broadcast(UICommand.java:296)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1255)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:77)
... 22 more
这是我完整的Xhtml文件。
<p:dataTable id = "dataTableId" var = "pr" value = "#{dashboard.beanList}" >
<f:facet name="header">
<!-- edit button -->
<p:commandButton id="toggler1" type="button" value="Customize Columns" style="float:right" icon="ui-icon-calculator" />
<p:columnToggler datasource="dataTableId" trigger="toggler1" />
</f:facet>
<p:column>
<f:facet name="header"><h:selectBooleanCheckbox /> </f:facet>
<h:selectBooleanCheckbox />
</p:column>
<p:column>
<f:facet name="header"> UPC </f:facet>
<div class="help-tip">
<h:outputLabel value="#{pr.lUpc}" id="l1" />
</div>
</p:column>
<p:column>
<f:facet name="header"> Cost </f:facet>
<h:outputLabel value="#{pr.dCost}" />
</p:column>
<p:column>
<f:facet name="header"> SKU </f:facet>
<h:outputLabel value="#{pr.sSku}" />
</p:column>
<p:column>
<f:facet name="header"> ProductName </f:facet>
<h:outputLabel value="#{pr.sProductName}" id="l2" />
</p:column>
<p:column>
<p:commandButton id="btn" value="Edit" onclick = "getupc(#{pr.lUpc})" >
</p:commandButton>
</p:column>
</p:dataTable>
<p:panel header="Export All Data">
<h:commandLink value="export as excel sheet">
<p:dataExporter type="xls" target="dataTableId" fileName="myexcel" />
</h:commandLink>
</p:panel>
答案 0 :(得分:0)
尝试评论此行:
编辑按钮
->
答案 1 :(得分:0)
如果您将素数更新为6.0或更高版本,则它将检查excel的sheetName。它将检查f:facet的内部,如果包含任何值,它将在sheet0中打印该名称。如果没有值,则工作表将为空。然后它将返回异常。
答案 2 :(得分:0)
我遇到了同样的问题。
正如“Anand”在之前的回答中所说的,primefaces 将名称搜索到 facet 中。
我有这个代码:
<p:dataTable id="xxxxxxx" value="#{bean.xxxxxxxx}" var="row" scrollable="true" scrollHeight="800" style="margin-top:10px; " >
<f:facet name="header">
<p:outputPanel style="display:flex;justify-content:space-between; width:100%;">
<h:commandLink>
<p:graphicImage
style="width:21px;height: 21px;margin:2px"
name="images/excel.png"/>
<p:dataExporter type="xls" target="xxxxxxx" fileName="Detail" postProcessor="#{bean.postProcessXLS}" />
</h:commandLink>
</p:outputPanel>
</f:facet>
...........
发生同样的异常,但在像这样的方面添加了一个标签
<p:dataTable id="xxxxxxx" value="#{bean.xxxxxxxx}" var="row" scrollable="true" scrollHeight="800" style="margin-top:10px; " >
<f:facet name="header">
<p:outputPanel style="display:flex;justify-content:space-between; width:100%;">
<p:outputLabel value="xxxxxxxxx" escape="false" style="line-height: 2; font-size: 13px;"></p:outputLabel>
<h:commandLink>
<p:graphicImage
style="width:21px;height: 21px;margin:2px"
name="images/excel.png"/>
<p:dataExporter type="xls" target="xxxxxxx" fileName="Detail" postProcessor="#{bean.postProcessXLS}" />
</h:commandLink>
</p:outputPanel>
</f:facet>
...........
它有效...不要问我为什么...