Hi,
I am new to CAF application and I need a help as follows:
I have a list of images in database and I wanted to display in Async Table.
I created a service to get Image name and encoded image data from database, then I have added a DynamicImageURL porperty in Page Bean and implemented the following code in page bean, it displaying only the first image and repeating the same.
Let me know how to display multiple image from database.
public java.lang.String getDynamicImageURL() {
try {
IPortletURL actionUrl = createActionUrl();
actionUrl.setTargetAction("doStreamImage");
actionUrl.setAXSRFT(true);
//System.out.println("----getting image url:" + actionUrl.toString());
return "fe:" + 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
*/
@PortletAction
public String doStreamImage() {
System.out.println("---doStreamImage");
try {
//new FileInputStream( "C:\\path-to-dfs-sdk\\output\\09002329800130a8.pdf"));
// new FileInputStream("C:\\path-to-dfs-sdk\\output\\Koala.jpg"));
for(int i=0;i<this.getProcessImageList.getResult().getGetProcessImageListResponse().getGetProcessImageListOutput().getResults().length;i++){
BASE64Decoder decoder = new BASE64Decoder();
byte[] decodedBytes = decoder.decodeBuffer(this.getProcessImageList.getResult().getGetProcessImageListResponse().getGetProcessImageListOutput().getResults()[i].getImage());
InputStream inStream = new ByteArrayInputStream(decodedBytes);
streamFileToUser(inStream);
}
} catch (Exception e) {
e.printStackTrace();
}
return OUTCOME_OK;
}
private void streamFileToUser(InputStream inStreamPrm) throws Exception {
final InputStream inStream = inStreamPrm;
// 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";
String contentType = "image/jpeg";
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);
}
System.out.println("wrote to the outStream");
}
/*
* (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
}
});
}