PF-2.2.1 ImageCropper: "{0}: conversion Error occurred"

UI Components for JSF
Post Reply
KingdomHeart
Posts: 280
Joined: 25 Jun 2010, 01:18

15 Mar 2011, 06:21

Here is my simple code

Code: Select all

<p:growl id="msgs" showDetail="true"/>
<h:form>
    <h:outputText value="Crop Image" styleClass="labelText" style="margin-left: 10px;"/><br/>
    <table cellspacing="10">
         <tr>
               <td>
                    <p:imageCropper value="#{CropImage.croppedImage}" image="#{CropImage.me.profilePic}"
                                    initialCoords="225,75,300" aspectRatio="1.25"/>                    
               </td>
               <td style="vertical-align: top;">
                    <h:outputText value="My Thumb Nail" styleClass="labelText"/><br/>
                    <p:graphicImage value="#{CropImage.imageName}" styleClass="icon"/><br/><br/>
                    <p:commandButton value="Crop" actionListener="#{CropImage.crop}" update="msgs"/>
               </td>
          </tr>
      </table>
 </h:form>
Here is my bean

Code: Select all

@ManagedBean(name="CropImage")
@ViewScoped
public class CropImage {

    @ManagedProperty(value="#{SessionBean}")
    private SessionBean sessionBean;

    private User me;

    private CroppedImage croppedImage;

    private String imageName;

    private String ext;

    private static final Logger logger = Logger.getLogger(CropImage.class.getName());
    
    public CropImage() {
    }

    @PostConstruct
    public void init(){
        me = sessionBean.getMe();
        imageName = me.getProfilePic();
        //obtain the extension
        ext = imageName.substring(imageName.lastIndexOf("."), imageName.length());
    }

    public String getImageName() {
        return imageName;
    }

    public void setImageName(String imageName) {
        this.imageName = imageName;
    }
    
    public SessionBean getSessionBean() {
        return sessionBean;
    }

    public void setSessionBean(SessionBean sessionBean) {
        this.sessionBean = sessionBean;
    }
    
    public User getMe() {
        return me;
    }

    public void setMe(User me) {
        this.me = me;
    }

    public CroppedImage getCroppedImage() {
        return croppedImage;
    }

    public void setCroppedImage(CroppedImage croppedImage) {
        this.croppedImage = croppedImage;
    }
    
    public String crop(){
        ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
        UUID uuid = UUID.randomUUID();
        imageName = servletContext.getInitParameter("resources") + File.separator;
        imageName += "cropped" + File.separator + uuid.toString() + ext;        
        FileImageOutputStream imageOutput;
        try {
            imageOutput = new FileImageOutputStream(new File(imageName));
            imageOutput.write(croppedImage.getBytes(), 0, croppedImage.getBytes().length);
            imageOutput.close();
        } catch (FileNotFoundException e) {
            logger.log(Level.SEVERE, e.getMessage());
        } catch (IOException e) {
            logger.log(Level.SEVERE, e.getMessage());
        }
        return null;
    }
}

When i click the "Crop" button, "{0}: Conversion Error Occurred" is what my growl message display. Help please. I think my croppedImage is null.
Last edited by KingdomHeart on 15 Mar 2011, 20:31, edited 4 times in total.

Mojarra 2.1.10, Glassfish 3.1, Tomcat 7, Primeface 3.3.1
IE 6-8, FireFox 10-13
MAC OSX Lion, Windows XP, 7

KingdomHeart
Posts: 280
Joined: 25 Jun 2010, 01:18

15 Mar 2011, 16:39

Help please

Mojarra 2.1.10, Glassfish 3.1, Tomcat 7, Primeface 3.3.1
IE 6-8, FireFox 10-13
MAC OSX Lion, Windows XP, 7

KingdomHeart
Posts: 280
Joined: 25 Jun 2010, 01:18

15 Mar 2011, 18:49

I also not very convince that the code on the showcase is correct

Code: Select all

<p:graphicImage id="localCroppedImage"  
                    value="barca/#{imageCropperBean.newImageName}.jpg" />  
When I look at the `imageCropperBean`, I dont see attribute `newImageName`.

Mojarra 2.1.10, Glassfish 3.1, Tomcat 7, Primeface 3.3.1
IE 6-8, FireFox 10-13
MAC OSX Lion, Windows XP, 7

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 6 guests