0

I'm using PrimeFaces upload to store image as array of byte in mysqldb. Now I want to retrieve these images from Db and display it in a datatable. When my datatable is populated , some images are displayed and some are not. I think JSF is having issue while rendering the image.
Here is my code:

My datatable:

     <p:dataTable id="dta" value="#{CarComponent.carList}" var="current" rows="100" paginator="true" paginatorPosition="bottom">
        <p:column>
            <p:graphicImage value="#{current.tempPhoto}"/>
        </p:column>
     </p:datatable>

Entity class:

      Table(catalog = "cardb", name = "car")
      public class Car implements Serializable {

      //some fields....

      @Column(name = "CAR_ID", length = 50, nullable = false)
      @Basic(fetch = FetchType.EAGER)
      @Id
      @XmlElement
      String carId;

      @Column(name = "CAR_IMG", columnDefinition = "LONGBLOB")
      @Basic(fetch = FetchType.EAGER)
      @Lob
      @XmlElement
      byte[] carImg;

      @Transient
      StreamedContent carPicture;

      //getters and setters
      }

CarComponentImpl.Java

  @Scope("session")
  @Component("CarComponent")
  public class CarComponentImpl implements CarComponent{

         //some declarations
         private List<Car> carList;

         public initialiseCar(){
              carList = carDao.findAllCars();

              for(Car cars: carList){
              car.setCarPicture(new DefaultStreamedContent(new ByteArrayInputStream(car.getCarImg()), car.getCarId().toString()+"image/png"));
              }
      }

     //Getter and setters of car list
}

Please help if you have a solution. The image is stored in DB but it does not display all the time.

Kukeltje
  • 11,924
  • 4
  • 19
  • 44
Alina
  • 403
  • 3
  • 8
  • 15

0 Answers0