How to show different image for different records in CellList by GWT

230 Views Asked by At

I have a CellList with AbstractCell. There are some text fields and one picture for each record, just like friend list, everybody has his/her own picture. In GWT showcase, the CellList sample gives one picture to all person with AbstractImagePrototype.create(imageResource). It is not a real world case. How to show these pictures in GWT?

I tried for 1 night with ClientBundle, only got result like 1 static picture in 1 main panel. Also, I don’t know where these pictures should be placed, in MySql’s Blob column or just in file system. Can you give me some suggestion on GWT side or server side? Thanks a lot.

Just now, I saw someone suggested a servlet on server side to provide these pictures. But it will cause another server access, and another permission check should be done on it. Can these pictures be downloaded with text data of CellList and show in browser together? thanks.

In 2.5rc, AbstractCell can work with UiRender with ui.xml. If it works with ui.xml fine, it will be the best solution.

1

There are 1 best solutions below

0
On

Well it depends how do you transmit the pictures of each user to your GWT app.
ClientBundle is not a good fit as it defines resources during compile time and I guess the avatar images of your users are quite dynamic (i.e new users, users changing picture, etc).

So you have two solutions:

  1. Add the actual image content (base64 encoded) to a field in your DTO that backs your CellListand in the render method of your AbstractCell just create an Image on the fly.
  2. Add the image url to a field in your DTO and in render method of your AbstractCell you can just create a Image or <a href= with the corresponding url.

Solution 2 will create a separate HTTP request for each image. Solution 1 won't, however the amount of data you transmit to the client will increase.

Regarding storage:

Storing them as blob field in the database is easier because when you delete the user record also the image will be automatically deleted. However your database size will increase and that's always an issue for backup.