[jboss-user] [JBoss Portal Users] - Re: ava.lang.ClassCastException: org.jboss.portal.portlet.im
guenther.herndl@softcon.de
do-not-reply at jboss.com
Tue Sep 8 12:10:28 EDT 2009
To day I tried a more seam like way:
/**
*
*/
package de.softcon.ivory.invserver.action.report;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import org.jboss.portal.portlet.impl.jsr168.api.ActionResponseImpl;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Import;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.core.Manager;
import org.jboss.seam.document.ByteArrayDocumentData;
import org.jboss.seam.document.DocumentData;
import org.jboss.seam.document.DocumentStore;
import org.jboss.seam.log.Log;
/**
* @author mbaumgar
*
*/
@Name("downloadComponent")
@Import("org.jboss.seam.pdf")
public class DownloadComponent
{
@In private Manager manager;
@In(create = true, value = "#{org.jboss.seam.document.DocumentStore}") private DocumentStore documentStore;
@In(value = "#{facesContext.externalContext}")
private ExternalContext externalContext;
/*
@In(value = "#{org.jboss.seam.faces.facesContext}")
private FacesContext facesContext;
*/
@Logger
private Log log;
public void download(String filename, File reportFile)
{
int read = 0;
byte[] bytes = new byte[1000];
// ActionResponseImpl res = (ActionResponseImpl)FacesContext.getCurrentInstance().getExternalContext().getResponse();
// HttpServletResponseWrapper response =(HttpServletResponseWrapper)FacesContext.getCurrentInstance().getExternalContext().getResponse();
ActionResponseImpl res = (ActionResponseImpl) externalContext.getResponse();
// HttpServletResponseWrapper response = res.getRealResponse();
// response.setContentType("application/xls");
// response.setContentLength((int) reportFile.length());
// response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\";");
// log.info("Content-Disposition attachment; filename=\"" + filename + "\";");
// log.error("Content-Disposition attachment; filename=\"" + filename + "\";");
try
{
// ServletOutputStream os = response.getOutputStream();
ByteArrayOutputStream os = new ByteArrayOutputStream();
FileInputStream fis = new FileInputStream(reportFile);
while ((read = fis.read(bytes)) != -1)
{
os.write(bytes, 0, read);
}
fis.close();
//
// os.flush();
// os.close();
byte[] binaryData = os.toByteArray();
DocumentData data = new ByteArrayDocumentData("report",
new DocumentData.DocumentType("pdf", "application/pdf"),
binaryData);
String docId = documentStore.newId();
documentStore.saveData(docId, data);
String documentUrl =
documentStore.preferredUrlForContent(
data.getBaseName(),
data.getDocumentType().getExtension(),
docId);
FacesContext.getCurrentInstance().getExternalContext().redirect(
manager.encodeConversationId(documentUrl));
// FacesContext.getCurrentInstance().getExternalContext().redirect(reportFile.toURI().toString());
// FacesContext.getCurrentInstance().responseComplete();
// facesContext.responseComplete();
}
catch (Exception e)
{
if (log.isErrorEnabled())
{
log.error(DownloadComponent.class, e);
}
}
}
}
But the injections did not succed. I got:
org.jboss.seam.RequiredException: @In attribute requires non-null value: downloadComponent.#{org.jboss.seam.document.DocumentStore}
at org.jboss.seam.Component.getValueToInject(Component.java:2335)
I use PorteltBridge Version CR2 with SEAM jboss-seam-2.1.2.CR2
Any hints how to correct generate PDF an XLS Files and download them with correct filename and extension (.pdf and .xls) are welcome.
Kind regards
Günther Herndl
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4254029#4254029
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4254029
More information about the jboss-user
mailing list