2013-06-21 28 views
4

我只是複製了primefaces showcase上的示例,但未顯示選擇圖像的區域。在展示中,它看起來很簡單。PrimeFaces imageCropper不顯示可選區域

我的頁面:

<ui:composition 
    xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:ui="http://java.sun.com/jsf/facelets" 
    xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:p="http://primefaces.org/ui"> 

<h:form> 

<p:imageCropper value="#{uploadMB.croppedImage}" id="imageCropper" 
image="/images/banner.jpg" /> 


</h:form> 

</ui:composition> 

我BackBean:

@ManagedBean 
public class UploadMB implements Serializable{ 

    private static final Logger logger = Logger.getLogger(UploadMB.class.getName()); 

    private CroppedImage croppedImage; 
    private String newImageName; 

    public String crop() { 
     if(croppedImage == null) 
      return null; 

     setNewImageName(getRandomImageName()); 
     ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext(); 
     String newFileName = servletContext.getRealPath("") + File.separator + "images" + File.separator + "barca" + File.separator + getNewImageName() + ".jpg"; 

     FileImageOutputStream imageOutput; 
     try { 
      imageOutput = new FileImageOutputStream(new File(newFileName)); 
      imageOutput.write(croppedImage.getBytes(), 0, croppedImage.getBytes().length); 
      imageOutput.close(); 
     } catch (FileNotFoundException e) { 
      e.printStackTrace(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 

     return null; 
    } 

    private String getRandomImageName() { 
     int i = (int) (Math.random() * 100000); 

     return String.valueOf(i); 
    } 

    public String getNewImageName() { 
     return newImageName; 
    } 

    public CroppedImage getCroppedImage() { 
     return croppedImage; 
    } 

    public void setCroppedImage(CroppedImage croppedImage) { 
     this.croppedImage = croppedImage; 
    } 

    public void setNewImageName(String newImageName) { 
     this.newImageName = newImageName; 
    } 

是否有可能缺少一些庫?或另一個配置選項?我只是下載了primefaces 3.5 jar,並把它放到我的classpath中。

感謝

+0

我有完全相同的問題 – pasql

回答

0

是您在%WEBAPP_ROOT%/圖片/ banner.jpg圖像

你們能通過HTTP URL(瀏覽器)來訪問你的形象?

0

你是否建立了crop99的initialCoords屬性:「x,y,w,h」? 您也可以設置aspectRatiominSize