dev@javaserverfaces.java.net

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 =
context.getApplication().createComponent(HtmlPanelGrid.COMPONENT_TYPE);
        grid.setColumns(someCollectionOfURIs.size());
        for (String uri : someCollectionOfURIs) {
            HtmlGraphicImage image =
context.getApplication().createComponent(HtmlGraphicImage.COMPONENT_TYPE);
            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
binding="#{whateverBean.grid}"/>

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.