i generated a temp image saved on the session with fileUpload.
then i passed the url to the image cropper image property but i need to especify the jsessionid concatenated in the url for don't get a NullPointException on ImageCropperRendered.java:141 (this is because internally create a new client to the server, diferent from the browser, to get the image. this is why a i need to concatenate jsessionid)
but the function "String getFormat(String path)" in ImageCropperRendered fail to detect the format when it has jsessionid concatenated.
i attach a screen shot of this
this is on PrimeFaces 3.2
[PF3.2] Image Cropper don't support on fly session images
ImageCropper doesn't support dynamic images. I think your problem is related to this.
There are issues about imageCropper here:
http://code.google.com/p/primefaces/iss ... il?id=3751
http://code.google.com/p/primefaces/iss ... il?id=1603
There are issues about imageCropper here:
http://code.google.com/p/primefaces/iss ... il?id=3751
http://code.google.com/p/primefaces/iss ... il?id=1603
from your first issue you only need to append jsessionid to the url in the component, like this:
image="http://#{request.serverName}:#{request.serverPort}#{request.contextPath}/uploadimagencrop/subida.jpeg;jsessionid=#{session.id}"
then you will get error of the format.
the problem is the behaviour of
protected String getFormat(String path) {
String[] pathTokens = path.split("\\.");
return pathTokens[pathTokens.length - 1];
}
in ImageCropperRendered.java
this is getting the format direct from url, instead of getting the format from the header http of the response(contentType? image/JPEG PNG, etc)
by the way, why ImageCropperRendered class , in "BufferedImage getSourceImage(FacesContext context, String imagePath)" has a distinction of is External or not? I think it should always be treated as external (http), Then get the format from http headers, content type.
something like this
String type = null;
URL u = new URL(fileUrl);
URLConnection uc = null;
uc = u.openConnection();
type = uc.getContentType();
return type;
image="http://#{request.serverName}:#{request.serverPort}#{request.contextPath}/uploadimagencrop/subida.jpeg;jsessionid=#{session.id}"
then you will get error of the format.
the problem is the behaviour of
protected String getFormat(String path) {
String[] pathTokens = path.split("\\.");
return pathTokens[pathTokens.length - 1];
}
in ImageCropperRendered.java
this is getting the format direct from url, instead of getting the format from the header http of the response(contentType? image/JPEG PNG, etc)
by the way, why ImageCropperRendered class , in "BufferedImage getSourceImage(FacesContext context, String imagePath)" has a distinction of is External or not? I think it should always be treated as external (http), Then get the format from http headers, content type.
something like this
String type = null;
URL u = new URL(fileUrl);
URLConnection uc = null;
uc = u.openConnection();
type = uc.getContentType();
return type;
i created a solution for this:
extending the render kit and the render class.
on faces-config:
<render-kit>
<renderer>
<component-family>org.primefaces.component</component-family>
<renderer-type>org.primefaces.component.ImageCropperRenderer</renderer-type>
<renderer-class>org.primefaces.component.imagecropper.TrollFacesImageCropperRenderer</renderer-class>
</renderer>
</render-kit>
on the class:
package org.primefaces.component.imagecropper;
import java.net.URL;
import java.net.URLConnection;
/**
*
* @author RyuChile
*/
public class TrollFacesImageCropperRenderer extends ImageCropperRenderer {
@Override
protected String getFormat(String path) {
String contentType = null;
try {
URL url = new URL(path);
URLConnection connection = url.openConnection();
connection.connect();
contentType = connection.getContentType();
}catch (Exception ex) {
throw new RuntimeException("Connection to the url failed",ex);
}
if(contentType == null) {
throw new RuntimeException("Problem getting url contentType is null!");
}
String format = contentType.toLowerCase().trim().replace("image/","");
if(format == null || format.length() == 0){
throw new RuntimeException("Unknow image mime type");
}
if(format.contains(";")) //contains a semicolon
{
format = format.split(";")[0];
}
if(format == null || format.length() == 0){
throw new RuntimeException("Unknow image mime type");
}
System.out.println("the format is: " + format);
return format;
}
}
now works well with session, but i think i break the behaviour when is internal (file)
extending the render kit and the render class.
on faces-config:
<render-kit>
<renderer>
<component-family>org.primefaces.component</component-family>
<renderer-type>org.primefaces.component.ImageCropperRenderer</renderer-type>
<renderer-class>org.primefaces.component.imagecropper.TrollFacesImageCropperRenderer</renderer-class>
</renderer>
</render-kit>
on the class:
package org.primefaces.component.imagecropper;
import java.net.URL;
import java.net.URLConnection;
/**
*
* @author RyuChile
*/
public class TrollFacesImageCropperRenderer extends ImageCropperRenderer {
@Override
protected String getFormat(String path) {
String contentType = null;
try {
URL url = new URL(path);
URLConnection connection = url.openConnection();
connection.connect();
contentType = connection.getContentType();
}catch (Exception ex) {
throw new RuntimeException("Connection to the url failed",ex);
}
if(contentType == null) {
throw new RuntimeException("Problem getting url contentType is null!");
}
String format = contentType.toLowerCase().trim().replace("image/","");
if(format == null || format.length() == 0){
throw new RuntimeException("Unknow image mime type");
}
if(format.contains(";")) //contains a semicolon
{
format = format.split(";")[0];
}
if(format == null || format.length() == 0){
throw new RuntimeException("Unknow image mime type");
}
System.out.println("the format is: " + format);
return format;
}
}
now works well with session, but i think i break the behaviour when is internal (file)
-
- PrimeFaces Core Developer
- Posts: 3979
- Joined: 03 Dec 2010, 14:11
- Location: Bavaria, DE
- Contact:
Create an issue please - jsessionid must be supported.
Thomas Andraschko
PrimeFaces | PrimeFaces Extensions
Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE
Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko
PrimeFaces | PrimeFaces Extensions
Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE
Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko
Okey
There is it: http://code.google.com/p/primefaces/iss ... il?id=3923
There is it: http://code.google.com/p/primefaces/iss ... il?id=3923