SEAM excel generation fails when using templateURI
Environment
- JBoss Enterprise Application Platform (EAP) 5
- SEAM
Issue
When using the "templateURI" property of
<e:workbook type="jxl" filename="GeneratedSpreadsheet.xls"
xmlns:e="http://jboss.com/products/seam/excel"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:s="http://jboss.com/products/seam/taglib"
xmlns:rich="http://richfaces.org/rich"
xmlns:h="http://java.sun.com/jsf/html"
templateURI="/directory/ExcelTemplate.xls">
JBoss throws the following exception:
2013-05-08 09:10:27,329 SEVERE [facelets.viewhandler] (http-127.0.0.1-8080-2) Error Rendering View[/directory/RendersExcel.xhtml]
org.jboss.seam.excel.ExcelWorkbookException: Could not create workbook
at org.jboss.seam.excel.jxl.JXLExcelWorkbook.createWorkbook(JXLExcelWorkbook.java:368)
at org.jboss.seam.excel.ui.UIWorkbook.encodeBegin(UIWorkbook.java:313)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:928)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:933)
at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
...
Caused by: java.lang.NullPointerException
at jxl.read.biff.File.<init>(File.java:91)
at jxl.Workbook.getWorkbook(Workbook.java:268)
at jxl.Workbook.getWorkbook(Workbook.java:253)
at org.jboss.seam.excel.jxl.JXLExcelWorkbook.createWorkbook(JXLExcelWorkbook.java:360)
... 53 more
Resolution
Move /directory/ExcelTemplate.xls to WEB-INF/classes.
Root Cause
The problem comes from the directory not being part of the web context classpath, which by default, only adds WEB-INF/classes, so /directory/ExcelTemplate.xls refers to the root of the web context classpath and not the root of the .war deployment.
Moving /directory to WEB-INF/classes makes it part of the web context classpath.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
