jeudi 2 avril 2015

dispalying Byte Arrya as Image in JSF 2.0

I have a image as byte[] in my bean. User can upload image using <h:inputFile/>. As soon as user clicks upload the image should be displayed in the page(Should not be saved in DB/Folder). I tried using Base64 convertion but in IE it's displaying only 32KB size image. Below is my xhtml code.

<h:form id="signatureform" enctype="multipart/form-data"> <h:inputFile id="inputFile" label="file1" value="#{bean.part}"/> <h:commandButton id="upButton" type="submit" action="#{bean.uploadSignature}" value="Upload" styleClass="commandButton"> </h:commandButton> </h:form>

<h:graphicImage url="data:image/jpg;base64,#{bean.encodedImage}" width="275px" height="75px"></h:graphicImage>

My Java code is



private String encodedImage ;
private Part part;
//getters and setters
public String uploadSignature() throws IOException {

InputStream inputStream = null;
try {
inputStream = part.getInputStream();
encodedImage = new String(Base64.encode(selectedColumnBean.getLnOffSignature()));
} catch (Exception e) {

} finally {
if (inputStream != null) {
inputStream.close();
}
}
return SUCCESS;
}




I have tried with <a4j:mediaOutput/> but no help. Please help me to resolve it.


Aucun commentaire:

Enregistrer un commentaire