当我滚动到表和表加载它的内容,我的图片的底部(图片来自StreamResource被嵌入式,我存储我的图片在数据库中的BLOB)得到破碎。破碎的形象7.6.3
包含的第一行表格嵌入式图像显示得很好,但是当我向下滚动时,看起来不错的图片会被破坏。
getAllPartners方法(在这里我加载从数据库团块图像):
public static Vector<PartnerDto> getAllPartner() {
Vector<PartnerDto> result = null;
PreparedStatement st = null;
Connection conn = null;
ResultSet rs = null;
try {
conn = Connect.getConnection();
String sql = "select part_id,name, surname, picture from partner order by name, surname ";
st = conn.prepareStatement(sql);
System.out.println(sql);
st.execute();
rs = st.getResultSet();
result = new Vector<PartnerDto>();
while (rs.next()) {
PartnerDto dto = new PartnerDto();
dto.setPart_id(rs.getInt("part_id"));
dto.setName(rs.getString("name"));
dto.setSurname(rs.getString("surname"));
Blob imageBlob = rs.getBlob("picture");
if(imageBlob!=null){
InputStream binaryStream = imageBlob.getBinaryStream(1, imageBlob.length());
dto.setPicture(binaryStream);
}else{
dto.setPicture(null);
}
result.addElement(dto);
}
} catch (SQLException e) {
result = null;
e.printStackTrace();
System.out.println(e);
} finally {
Connect.closeConnection(rs, st, conn);
}
return result;
}
我的表(tPartners)initalization:
tPartners.addContainerProperty("Slika uporabnika", Embedded.class, null);
tPartners.addContainerProperty("Ime", String.class, null);
tPartners.addContainerProperty("Priimek", String.class, null);
tPartners.addContainerProperty("Rojstni datum", String.class, null);
tPartners.addContainerProperty("Rojstni kraj", String.class, null);
tPartners.addContainerProperty("Naslov", String.class, null);
tPartners.addContainerProperty("Pošta", String.class, null);
tPartners.addContainerProperty("Emšo", String.class, null);
tPartners.addContainerProperty("Šola", String.class, null);
tPartners.addContainerProperty("Razred", String.class, null);
tPartners.addContainerProperty("Poklic", String.class, null);
tPartners.addContainerProperty("Telefon", String.class, null);
tPartners.addContainerProperty("Mail", String.class, null);
tPartners.addContainerProperty("Klubska številka", String.class, null);
tPartners.addContainerProperty("Številka kartice", String.class, null);
tPartners.addContainerProperty("Datum včlanitve", String.class, null);
tPartners.addContainerProperty("Opomba", String.class, null);
tPartners.addContainerProperty("File type", String.class, null);
tPartners.setSelectable(true);
tPartners.setImmediate(true);
代码波纹管展示了如何我负荷图像表:
//get all partners
Vector<PartnerDto> vResutl = DBLogika.searchPartner(text);
for (int i = 0; i < vResutl.size(); i++) {
//class that represent PartnerDto
PartnerDto dto = vResutl.elementAt(i);
String bd = "";
String din = "";
if (dto.getBorn_date() != null) {
bd = sdf.format(dto.getBorn_date());
}
if (dto.getDate_in() != null) {
din = sdf.format(dto.getDate_in());
}
Embedded emb=new Embedded();
StreamResource.StreamSource source = new StreamResource.StreamSource() {
public InputStream getStream() {
//get inputstream from database, I save my image as longblob in database
return dto.getPicture();
}
};
//uniq name for every file
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmssSSS");
String filename = "mytablepic" + df.format(new Date()) + ".png";
StreamResource sourceone=new StreamResource(source, filename);
emb.setHeight("200px");
emb.setWidth("150px");
emb.setSource(dto.getPicture()==null? new ThemeResource("images/user_pic.jpg"): sourceone);
tPartners.addItem((new Object[] {emb, dto.getName(), dto.getSurname(), bd, dto.getBorn_place(), dto.getAddress(),
dto.getPostDto().getPostName(), dto.getEmso(),
dto.getSchool(), dto.getPartClass(), dto.getJob(), dto.getPhone(),
dto.getMail(), dto.getClub_number(), dto.getCard_number(),
din, dto.getDesc(),dto.getFileextention()}), dto);
}
我做错了什么?显示我的问题
两个图像:
- how looks first time when I load content in table
- broken image picture, when I scroll for example to the top, and then back to top
我的Tomcat 8.0服务器上运行我的本地主机上的应用程序。
当我用Firebug检查Firefox中的图像时,它告诉我:无法加载图像。
不知怎的,当我滚动和表需要加载它含量的不同,图像会出现问题...
我怎么能解决这个问题?请帮我:-)
请考虑写出“一个合适”的答案(不只是一个链接,明天可能会消失) – cfrick
当然,我编辑我的解决方案。 – slodeveloper