Hi Eric,
I am having the same problem trying to display the bytes as an image on the screen.
But the way of linking image url to the action that does the streaming implementation you provided does not work because the action does not get invoked after all. I refer to the article below which I tried.
[url]http://tech.forums.softwareag.com/techjforum/posts/list/14924.page[/url]
here is my action below, could you advise what is wrong, or is it another way doing this task.
Thank you
Leonard
/**
* Use this custom method to build the action url that you can bind to the
* Image control value.
*/
public String getDynamicImageURL() {
try {
IPortletURL actionUrl = createActionUrl();
// set the target action to an expression that resolves to the JSF action
actionUrl.setTargetAction("#{activePageBean.doStreamImage}");
System.out.println("----getting image url:" + actionUrl.toString());
return actionUrl.toString();
} catch (Exception e) {
e.printStackTrace();
error(e);
}
return null;
}
/**
* Use this custom action method to retrieve the image data and stream it
* back
*/
public String doStreamImage() {
System.out.println("---doStreamImage");
IFileExportBean fileExportBean = null;
try {
streamFileToUser();
} catch (Exception e) {
e.printStackTrace();
}
return OUTCOME_OK;
}
private void streamFileToUser() throws Exception{
final InputStream inStream = new BufferedInputStream(
new FileInputStream("C:\\path-to-dfs-sdk\\output\\09002329800130a8.pdf"));
//stream the file back to the user
streamFileDataToResponse(new IFileExportBean() {
/* (non-Javadoc)
* @see com.webmethods.caf.faces.bean.IFileExportBean#isDownloadForced()
*/
public boolean isDownloadForced() {
return false; //open the file inline rather than forcing the user to choose what to do with it.
}
/* (non-Javadoc)
* @see com.webmethods.caf.faces.bean.IFileExportBean#getExportContentLength()
*/
public int getExportContentLength() {
return IFileExportBean.UNKNOWN_CONTENT_LENGTH; //use this for unknown file size, or the actual file size if known.
}
/* (non-Javadoc)
* @see com.webmethods.caf.faces.bean.IFileExportBean#getExportContentType()
*/
public String getExportContentType() {
String contentType = "application/pdf";
return contentType;
}
/* (non-Javadoc)
* @see com.webmethods.caf.faces.bean.IFileExportBean#getExportFileName()
*/
public String getExportFileName() {
return "export.pdf";
}
/* (non-Javadoc)
* @see com.webmethods.caf.faces.bean.IFileExportBean#isExportBinary()
*/
public boolean isExportBinary() {
return true;
}
/* (non-Javadoc)
* @see com.webmethods.caf.faces.bean.IFileExportBean#writeExportBytes(java.io.OutputStream)
*/
public void writeExportBytes(OutputStream outStream) throws IOException {
byte [] buffer = new byte[1024 * 8]; //8k buffer
int len = -1;
while ( (len = inStream.read(buffer)) != -1 ) {
//copy the buffer to the outstream
outStream.write(buffer, 0, len);
}
}
/* (non-Javadoc)
* @see com.webmethods.caf.faces.bean.IFileExportBean#writeExportText(java.io.PrintWriter)
*/
public void writeExportText(PrintWriter arg0) {
//not used, since the export is a binary file
}
});
}
/**
* Action Event Handler for the control with id='button'
*/
public String button_action() {
String url = getDynamicImageURL();
System.out.println("----url: "+ url);
FacesContext context = getFacesContext();
url = "C:\\path-to-dfs-sdk\\output\\09002329800130a8.pdf";
url = context.getExternalContext().encodeResourceURL(url);
System.out.println("url: --"+ url);
// getHtmlGraphicImage().setUrl(url);
getHtmlGraphicImage().setValue(url);
System.out.println("url: ----"+ getHtmlGraphicImage().getUrl());
return null;
}
/**
* Getter method for the control with id='defaultForm:htmlGraphicImage'
*/
public com.webmethods.caf.faces.component.standard.HtmlGraphicImage getHtmlGraphicImage() {
return (com.webmethods.caf.faces.component.standard.HtmlGraphicImage)findComponentInRoot("defaultForm:htmlGraphicImage");
}
public com.webmethods.caf.is.wsclient.investecpoc.flows.front.documentum.doczwsd.GetContent1 getGetContent() {
if (getContent == null) {
getContent = (com.webmethods.caf.is.wsclient.investecpoc.flows.front.documentum.doczwsd.GetContent1)resolveExpression("#{GetContent}");
}
resolveDataBinding(GETCONTENT_PROPERTY_BINDINGS, getContent, "getContent", false, false);
return getContent;
}
public com.webmethods.caf.is.wsclient.investecpoc.ws.consumer.xpression.PublishAndReturnDocument getPublishAndReturnDocument() {
if (publishAndReturnDocument == null) {
publishAndReturnDocument = (com.webmethods.caf.is.wsclient.investecpoc.ws.consumer.xpression.PublishAndReturnDocument)resolveExpression("#{PublishAndReturnDocument}");
}
resolveDataBinding(PUBLISHANDRETURNDOCUMENT_PROPERTY_BINDINGS, publishAndReturnDocument, "publishAndReturnDocument", false, false);
return publishAndReturnDocument;
}
public com.webmethods.caf.is.wsclient.investecpoc.ws.consumer.xpression.PublishAndReturnDocument2 getPublishAndReturnDocument2() {
if (publishAndReturnDocument2 == null) {
publishAndReturnDocument2 = (com.webmethods.caf.is.wsclient.investecpoc.ws.consumer.xpression.PublishAndReturnDocument2)resolveExpression("#{PublishAndReturnDocument2}");
}
resolveDataBinding(PUBLISHANDRETURNDOCUMENT2_PROPERTY_BINDINGS, publishAndReturnDocument2, "publishAndReturnDocument2", false, false);
return publishAndReturnDocument2;
}
}
#MWS-CAF-Task-Engine#webMethods-BPMS#webMethods