I'm using the ImageCropper with <p:commandxxx async="true" etc. and I get everything to work.
So I can crop and image and load it back in another location the first time. But if i click the button a second time it doesn't load the second cropped image in the same spot. Is there a bug with ajax support for <p:command xxx /> I'm I doing something wrong.
Thanks,
Jason Hall
ImageCropper ajax problem
Below is my code:
Code: Select all
<!--<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" -->
<!-- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.prime.com.tr/ui">
<h:head>
</h:head>
<h:body>
#{imageCropperBean.hi}
<h:form>
<h:panelGrid columns="2">
<p:imageCropper value="#{imageCropperBean.croppedImage}" image="/images/dbPhoto2.jpg" />
<h:graphicImage id="croppedImage" value="#{imageCropperBean.newImage}" />
<p:commandButton value="Crop" action="#{imageCropperBean.crop}" ajax="true" async="true" update="croppedImage"/>
</h:panelGrid>
<h:commandButton value="Crop2" action="#{imageCropperBean.crop}" />
<h:graphicImage id="jason" value="#{imageCropperBean.newImage}">
<p:draggable />
</h:graphicImage>
</h:form>
#{imageCropperBean.newImage}
<p:editor/>
</h:body>
</html>
Code: Select all
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Logger;
//import javax.enterprise.context.SessionScoped;
import javax.faces.context.FacesContext;
import javax.imageio.stream.FileImageOutputStream;
import javax.inject.Named;
import javax.servlet.ServletContext;
import org.primefaces.component.imagecropper.ImageCropper;
import org.primefaces.model.CroppedImage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.bean.SessionScoped;
@ManagedBean
@SessionScoped
public class ImageCropperBean
{
private CroppedImage croppedImage;
private String crop;
private String hi="Hi Jason Hall";
private String newImage;
public String getNewImage() {
return newImage;
}
public void setNewImage(String newImage) {
this.newImage = newImage;
}
public String getHi() {
return hi;
}
public void setHi(String hi) {
this.hi = hi;
}
public CroppedImage getCroppedImage()
{
return croppedImage;
}
public void setCroppedImage(CroppedImage croppedImage)
{
this.croppedImage = croppedImage;
}
public static void main(String arg[])
{
ImageCropperBean i = new ImageCropperBean();
System.out.println(File.separator);
//i.crop();
}
public void setCrop()
{
}
public String crop()
{
String newFileName="";
System.out.println("Hi Jason Hall");
//Logger logger = Logger.getLogger("jason_log.txt");
ServletContext servletContext = (ServletContext)
FacesContext.getCurrentInstance().getExternalContext().getContext();
newFileName = servletContext.getRealPath("") + croppedImage.getOriginalFilename()+ "cropped2.jpg";
//logger.info(newFileName);
System.out.println("Location of Image: "+newFileName);
FileImageOutputStream imageOutput;
newImage = croppedImage.getOriginalFilename()+ "cropped2.jpg";
System.out.println("Location of Image (short path): "+newImage);
//newImage ="/images/dbPhoto2.jpg" ;
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 newFileName;
}
}
-
- Prime
- Posts: 18616
- Joined: 05 Jan 2009, 00:21
- Location: Cybertron
- Contact:
Showcase is working;
http://www.primefaces.org:8080/prime-sh ... erAjax.jsf
Are you sure browser does not cache your generated images?
http://www.primefaces.org:8080/prime-sh ... erAjax.jsf
Are you sure browser does not cache your generated images?
-
- Information
-
Who is online
Users browsing this forum: No registered users and 29 guests