Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: How to show an image data stored in database in jsf?

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to show an image data stored in database in jsf?

    Hi,
    Pls help me out on showing an image stored as blob data type in the db and i am retriving it and keeping it as inputstream,writing it to outpout stream but cann't display the output stream object in the jsf.

    Below is the code that i have written. Advise me if anything wrong with code.
    //method name in the bean
    public void showImageFrmLocal()
    InputStream fileInputStream = null;
    //here it get the image from db as fileInputStream
    fileInputStream = files.get(i).getFilesInputStream();
    fileInputStream = new BufferedInputStream(files.get(i).getFilesInputStre am());
    for (int length = 0; (length = fileInputStream.read(byteArray)) > 0 {
    //output.write(byteArray, 0, length);
    response.getOutputStream().write(byteArray, 0, length);
    }
    fileInputStream.close();
    }
    response.getOutputStream().close();
    FacesContext.getCurrentInstance().responseComplete ();
    FacesContext.getCurrentInstance().renderResponse() ;

    And the jsf is

    <h:commandLink id="imagId1" value="View Image" style="position: relative;"
    actionListener="#{Bean.showImageFrmLocal}">
    </h:commandLink>


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 262 Times in 231 Posts

    Default Re: How to show an image data stored in database in jsf?

    Please use [code=java] before your code and [/code] after your code. It makes the code all pretty and keeps the evil smiley face from hiding symbols in the code. (<---lol@)



    but cann't display the output stream object in the jsf.
    Why not? What is the problem? Is there an error message? Do you get different results than expected?



    Advise me if anything wrong with code.
    Does it compile, run, and produce the desired results? What is it supposed to do? Does it do that?




    I think there should be some safety feature guarding the stream. What will happen if you lose connection in the middle of the stream? (A predictable and likely scenario)

  3. #3
    Junior Member
    Join Date
    Aug 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to show an image data stored in database in jsf?

    Thanks for ur reply...

    I am getting the warnings as:WARNING: JSF1095: The response was already committed by the time we tried to set the outgoing cookie for the flash. Any values stored to the flash will not be available on the next request.

    I changed my method a little bit that is,Writing the input stream object to StreamContent object defined in the primefaces and sending back to the jsf by using h:graphicImage tag..help me on this

Similar Threads

  1. how to write data to a pdf file which is stored on a sql database
    By cancer625 in forum Object Oriented Programming
    Replies: 3
    Last Post: January 22nd, 2012, 09:34 PM
  2. Trying to show change on Image based on pixel values
    By javaGurl in forum Algorithms & Recursion
    Replies: 1
    Last Post: September 20th, 2011, 03:49 PM
  3. I am trying to show database contents in the browser through servlets
    By abhiM in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 12th, 2011, 02:08 AM
  4. Beginner: Show Image in Label when Results Show Up
    By Big Bundy in forum Java Theory & Questions
    Replies: 3
    Last Post: April 4th, 2011, 02:43 PM
  5. J2ME-Show RMS data in tabular form
    By Sunil Raghuvanshi in forum Java ME (Mobile Edition)
    Replies: 1
    Last Post: January 24th, 2011, 07:06 AM