我正在使用PrimeFaces上传将图像存储为mysqldb中的字节数组。现在我想从Db中检索这些图像并将其显示在数据表中。填充我的数据表时,会显示一些图像,而某些图像则不会显示。我认为JSF在渲染图像时遇到了问题。
这是我的代码:
我的数据表:
<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>
实体类:
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
}
如果您有解决方案,请提供帮助。图像存储在DB中,但不会一直显示。