이미지 파일을 데이터베이스에 업로드하려고합니다. 이미지가 저장되기 전에 사용자에게 표시하고 싶습니다.요청 범위 Bean을 사용하여 이미지를 업로드했습니다.
요청 범위의 콩인 UserInfoBean
(요청 범위가 변경되지 않음)을 사용하여 데이터를 저장하려고했지만, 페인트가 호출 될 때 preview
바이트 []가 null입니다. preview
또는 image
을 저장할 수있는 방법이 있습니까? paintItem이 호출 될 때 UploadItem에 액세스 할 수 있습니까?
info.xhtml 코드 : UserInfoBean의
<a4j:outputPanel id="preview"
<a4j:mediaOutput id="imgPreview"
element="img"
mimeType="image/jpeg"
createContent="#{userInfo.paint}"
cacheable="false"
style="width:150px; height:100px;" />
<br/>
</a4j:outputPanel>
<a4j:outputPanel id="signatureStampDisplay">
<br/>
<rich:fileUpload fileUploadListener="#{userInfo.uploadImage}"
id="upload"
listHeight="40px"
acceptedTypes="#{userInfo.supportedTypes}"
ontyperejected="alert('Only JPG, GIF, PNG, BMP, and TIF files are accepted');"
maxFilesQuantity="1"
immediateUpload="true"
autoclear ="true"
disabled="#{userInfo.stampSet}">
<a4j:support event="onuploadcomplete"
limitToList="true"
reRender="preview"/>
</rich:fileUpload>
</a4j:outputPanel>
부, UploadItem
이미지와 byte[]
미리보기는 :
public void uploadImage(UploadEvent evt) throws IOException{
image = evt.getUploadItem();
if(image != null){
//preview is a byte[]
preview = FileUtils.readFileToByteArray(image.getFile());
}
}
public void paint(OutputStream stream, Object object) throws IOException{
if(preview != null){
stream.write(preview);
}
}
에 표시 한 후 사용
. 'a4j : mediaOutput'에 적절한'mimeType'을 설정해야합니다. –
@VasilLukach 불행하게도'paint'는'preview'을 null로 봅니다. 나는 당신의 추천 한 변경을했다, 그래도 고맙다. – zomgcopters
업로드가 성공적 이었습니까? 그렇다면 더 긴 범위 또는 DB를 사용하여 미리보기를 다른 위치에 저장하고 다시 칠하십시오. bean이 요청 범위이므로이 데이터를 사용할 수 없습니다. –