[jboss-user] [JBoss Portal Users] - Re: ava.lang.ClassCastException: org.jboss.portal.portlet.im

2009-09-10 Thread guenther.her...@softcon.de
If I use our default SEAM Solution:
/**
 * 
 */
package de.softcon.ivory.invserver.action.report;



import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Iterator;
import java.util.Map;

import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.portlet.PortletMode;
import javax.portlet.PortletModeException;
import javax.portlet.WindowState;
import javax.portlet.WindowStateException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponseWrapper;

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(value = #{facesContext.externalContext})
private ExternalContext externalContext;
@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 = 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();

FileInputStream fis = new FileInputStream(reportFile);

while ((read = fis.read(bytes)) != -1)
{
os.write(bytes, 0, read);
}
fis.close();

os.flush();
os.close();

FacesContext.getCurrentInstance().responseComplete();
}
catch (Exception e)
{
if (log.isErrorEnabled())
{
log.error(DownloadComponent.class, e);
}
}
}
}

I get the follwing exception with wrong file-names and lost extension (.pdf or 
.xls):

2009-09-10 11:51:08,161 DEBUG [org.jboss.seam.Component] trying to inject with 
EL expression: #{facesContext.externalContext}
2009-09-10 11:51:08,161 INFO  
[de.softcon.ivory.invserver.action.report.DownloadComponent] 
Content-Disposition attachment; filename=listOfAsset.pdf;
2009-09-10 11:51:08,161 ERROR 
[de.softcon.ivory.invserver.action.report.DownloadComponent] 
Content-Disposition attachment; filename=listOfAsset.pdf;
2009-09-10 11:51:08,161 DEBUG 
[javax.enterprise.resource.webcontainer.jsf.lifecycle] Exiting 
InvokeApplicationsPhase
2009-09-10 11:51:08,161 DEBUG [org.ajax4jsf.event.AjaxPhaseListener] Process 
after phase INVOKE_APPLICATION 5
2009-09-10 11:51:08,161 DEBUG [org.jboss.seam.jsf.SeamPhaseListener] committing 
transaction after phase: INVOKE_APPLICATION 5
2009-09-10 11:51:08,161 DEBUG [org.jboss.seam.transaction.UTTransaction] 
committing JTA transaction
2009-09-10 11:51:08,161 DEBUG [org.hibernate.transaction.CacheSynchronization] 
transaction before completion callback
2009-09-10 11:51:08,161 DEBUG [org.hibernate.jdbc.JDBCContext] before 
transaction completion
2009-09-10 11:51:08,161 DEBUG [org.hibernate.impl.SessionImpl] before 
transaction completion
2009-09-10 11:51:08,161 DEBUG [org.hibernate.ejb.AbstractEntityManagerImpl] 
automatically flushing session
2009-09-10 11:51:08,161 DEBUG [org.hibernate.impl.SessionImpl] automatically 
flushing session
2009-09-10 11:51:08,161 DEBUG 
[org.hibernate.event.def.AbstractFlushingEventListener] flushing session
2009-09-10 11:51:08,161 DEBUG 
[org.hibernate.event.def.AbstractFlushingEventListener] processing flush-time 
cascades
2009-09-10 11:51:08,161 DEBUG [org.hibernate.engine.Cascade] processing cascade 
ACTION_PERSIST_ON_FLUSH for: de.softcon.ivory.invserver.model.tenant.Tenant
2009-09-10 11:51:08,161 DEBUG [org.hibernate.engine.Cascade] done processing 
cascade ACTION_PERSIST_ON_FLUSH for: 
de.softcon.ivory.invserver.model.tenant.Tenant
..
Lines Deleted
..
2009-09-10 11:51:08,161 DEBUG [org.jboss.seam.contexts.FacesLifecycle]  End 
JSF request for /invserverproject/faces
2009-09-10 11:51:08,161 DEBUG 
[javax.enterprise.resource.webcontainer.jsf.timing]  [TIMING] - [516ms] : 
Execution time for phase (including any PhaseListeners) - 

[jboss-user] [JBoss Portal Users] - Re: ava.lang.ClassCastException: org.jboss.portal.portlet.im

2009-09-10 Thread guenther.her...@softcon.de
the download use the window-name from *-object.xml instead:
?xml version=1.0 encoding=UTF-8?

  
 parent-refdefault/parent-ref
 if-existsoverwrite/if-exists
 
 page-nameinvserverproject/page-name

window-nameinvserverprojectPortletWindow/window-name
instance-refinvserverprojectPortletInstance/instance-ref
center
0
initial-window-statemaximized/initial-window-state


  

  



View the original post : 
http://www.jboss.org/index.html?module=bbop=viewtopicp=4254374#4254374

Reply to the post : 
http://www.jboss.org/index.html?module=bbop=postingmode=replyp=4254374
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user



[jboss-user] [JBoss Portal Users] - Re: ava.lang.ClassCastException: org.jboss.portal.portlet.im

2009-09-08 Thread guenther.her...@softcon.de
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=bbop=viewtopicp=4254029#4254029

Reply to the post : 
http://www.jboss.org/index.html?module=bbop=postingmode=replyp=4254029

___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user