Re: Best way to show row of images

From: Ryan Lubke <Ryan.Lubke_at_Sun.COM>
Date: Mon, 03 Sep 2007 11:03:35 -0700

ChrisC wrote:
> Hi
> I want to show a table x wide, one deep which has an image shown in each
> cell.
> The image details are stored in a db, and the number of images is variable.
> That is, one way of thinking is that I need a horizontal dataTable.
> Can someone suggest the best way of doing this.
> Thanks
> Chris
Assuming that you have a way to obtain a specific image from the DB from
a URI, then
you could use a component binding with h:panelGrid.

Something like:

   public UIComponent getGrid() {
        FacesContext context = FacesContext.getCurrentInstance();
        HtmlPanelGrid grid =
        for (String uri : someCollectionOfURIs) {
            HtmlGraphicImage image =
            image.getAttributes().put("value", uri);
            // set what other attributes you need to have rendered on
each image
        return grid;

    so in your view, you'd have something like: <h:panelGrid

The next part of this would be having a separate servlet to serve the
images themselves when requested by the browser.
So the URIs might look like "/images/<db_unique_identifier_stuff>" with
the servlet mapped to "/images/*".

The servlet would take the unique identifier stuff, and return the
appropriate data via the ServletOutputStream.