2014-03-24 59 views
0

我工作的primefaces應用程序。我需要裁剪個人資料照片。一旦用戶想要的圖像部分和用戶提交它是獲得空指針異常。 getBytes()爲空。primefaces Image Cropper獲取空指針異常

這裏是我的代碼XHTML代碼:``

<p:dialog id="cropDlg" appendToBody="false" widgetVar="dlg" 
    showEffect="fade" hideEffect="explode" resizable="false" 
    modal="true" header="Edit Picture" 
    style="background-color:#FFFFFF"> 
    <h:form id="cropForm" enctype="multipart/form-data"> 
    <p:panel style="background-color: #FFFFFF" id="cropPanel"> 
     <p:messages /> 
     <div> 
     <p:imageCropper value="#{profileBean.image}" image="/profile?id=#{profileBean.profile.imageFileName}" /> 
     <h:commandButton value="crop" immediate="true" styleClass="profilebut" action="#{profileBean.handleCropFileUpload}" /> 
     </div> 
    </p:panel> 
    </h:form> 
</p:dialog> 

我的豆:

CroppedImage croppedImage; 

public void handleCropFileUpload() { 
    System.out.println("GET Bytes" + croppedImage.getBytes()); 
    FileImageOutputStream imageOutput; 
    try { 
    imageOutput = new FileImageOutputStream(file); 
    imageOutput.write(croppedImage.getBytes(), 0, 
    croppedImage.getBytes().length); 
    imageOutput.close(); 
    } catch (Exception e) { 
    e.printStackTrace(); 
    } 
} 

public CroppedImage getImage() { 
    return image; 
} 

public void setImage(CroppedImage image) { 
    this.image = image; 
} 

回答

0

從你h:commandButton刪除屬性immediate="true",它會工作。