-
1. Re: load an image from remote source
lvdberg Aug 6, 2009 10:23 AM (in response to rsathish_gandhi)Hi Satish,
You can use additional data sources for the s-tag. I use the
stream
and I've added a stream reader to a specific bean. Your stream reader can be based on whatever URL (with http for webbased and file for local access). I've included a basic example
public InputStream serveContent(String content){ InputStream s = null; try { URL url = new URL(content); s = url.openStream(); } catch (MalformedURLException e) { System.out.println(e.getMessage()); } catch (IOException e) { System.out.println(e.getMessage()); } return s; }
I call the function with:
Another possiility is to use the byte-array as source, which can be provided by your entity-bean. I use the combination of both in a table with icons and a tooltip. The icon is automatically generated and saved in the database together with the fullname of a file where I store the full-size image. Whenever I hoover over the image a tooltip shows the full-size image.
hopefully this helps.
Leo
-
2. Re: load an image from remote source
jjlang Aug 6, 2009 10:51 AM (in response to rsathish_gandhi)I had met a similar problem as yours. The client need to submit a excel file to the server. To implement, use a seam:fileUpload and create a byte array to accept its data, then format the byte data as excel file at the server side.
I think properly you format the byte data as jpeg file. -
3. Re: load an image from remote source
rsathish_gandhi Aug 6, 2009 3:48 PM (in response to rsathish_gandhi)Click HELP for text formatting instructions. Then edit this text and check the preview.
Hi Mr. Leo van den Berg
Thanks a lot it's running when i use URL class
But i tried to run using output stream i getting the errorerror is :
Caused by: java.lang.IllegalStateException: Servlet response already use Writer, OutputStream not possible
public byte[] getShowImage(){ int length = 0; byte[] bytes = null; FileInputStream in = null; try { in = new FileInputStream("C:/Documents and Settings/All Users/Documents/My Pictures/Sample Pictures/Sunset.jpg"); length = in.available(); bytes = new byte[length]; in.read(bytes); in.close(); } catch (FileNotFoundException e) { e.printStackTrace(); }catch (IOException e) { e.printStackTrace(); } FacesContext context = FacesContext.getCurrentInstance(); HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse(); try { response.setContentType("image/jpg"); response.setContentLength(length); response.getOutputStream().write(bytes); context.responseComplete(); } catch (IOException e) { e.printStackTrace(); } return bytes; }
-
4. Re: load an image from remote source
rsathish_gandhi Aug 6, 2009 3:50 PM (in response to rsathish_gandhi)Hi Mr. Leo van den Berg
Thanks a lot it's running when i use URL class But i tried to run using output stream i getting the error
error is :
Caused by: java.lang.IllegalStateException: Servlet response already use Writer, OutputStream not possible
public byte[] getShowImage(){ int length = 0; byte[] bytes = null; FileInputStream in = null; try { in = new FileInputStream("C:/Documents and Settings/All Users/Documents/My Pictures/Sample Pictures/Sunset.jpg"); length = in.available(); bytes = new byte[length]; in.read(bytes); in.close(); } catch (FileNotFoundException e) { e.printStackTrace(); }catch (IOException e) { e.printStackTrace(); } FacesContext context = FacesContext.getCurrentInstance(); HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse(); try { response.setContentType("image/jpg"); response.setContentLength(length); response.getOutputStream().write(bytes); context.responseComplete(); } catch (IOException e) { e.printStackTrace(); } return bytes; }
-
5. Re: load an image from remote source
lvdberg Aug 7, 2009 8:24 AM (in response to rsathish_gandhi)Hi Satish,
If it is your intention to load some binary resource and serve it to the user browser, you could use a bean which extends Abstractresource. Another option is to use the build in component DocumentStore.
Leo