Code: Select all
FileContent file = getFile("C:/path_to_file/test.jpg");
ByteArrayOutputStream baOut = new ByteArrayOutputStream();
InputStream inputStream = new FileInputStream(file.getFilePath());
int bytes = 0;
byte[] byteFile = new byte[1024];
while ((bytes = inputStream.read(byteFile)) != -1) {
baOut.write(byteFile, 0, bytes);
}
inputStream.close();
byte[] data = baOut.toByteArray();
resp.setContentLength(data.length);
resp.setContentType(file.getMimeType());
OutputStream outputStream = resp.getOutputStream();
outputStream.write(data);
baOut.close();
outputStream.close();
I am using the following in XHTML:
Code: Select all
<p:imageCropper value="#{cropperBean.croppedImage}"
image="/dyn_images/#{profile.image}.jpg"
initialCoords="10,10,50,50"/>
<p:commandButton value="Save"
action="#{cropperBean.crop}"
ajax="false">
</p:commandButton>
If I use the same image as a static image, like "/images/test.jpg", which exists in the web folders, it works fine ... the bean gets called.
I have been using PrimeFaces for a while now, and I am glad for the JSF 2.0 support. PF rocks!