Knowledge brings fear ... Prosthetic Conscious

Wednesday Oct 25, 2006

The other day, I started working on a new JSF-based portlet app ... essentially, a JSF app that would use the JSF-Portlet Bridge so it can be sucked into a portal. Without going into details, the app needed to draw a table where each cell contains one object from a set of objects. For example, think of a photo album. Each table cell contains a photo and some meta data about the photo perhaps.

I would have really though this is a common enough pattern that it'd be straightforward in JSF. Well, it's not. The only tabular-type components in JSF are panelGrid and dataTable. panelGrid does not allow a dynamic data sets; you must call out all of the cells statically. dataTable only supports a "one object per row" scenario, as opposed to per-cell as I needed.

For example, suppose I had a tag called dataGrid. I'd want to use it like this:

<h:dataGrid var="photo" value="#{album.photos}" columns="6">
  <h:cell>
    <h:panelGrid columns="1">
      <h:graphicImage url="#{photo.url}"/>
      <h:outputText value="#{photo.title}"/>
      ...
    </h:panelGrid>
  </h:cell>
<h:dataGrid>


But obviously, this tag doesn't exist. Not only doesn't it exist, it's not even possible to do, at all, without writing a custom tag or binding say a panelGrid and building it's contents programmatically (which sort of defeats the point of JSF). Writing a custom tag is an option, but when faced with the decision of whether to spend a week writing a custom tag or writing the entire app in the same amount of time, I chose the latter.

Another thing one would like to do in such a situation is to mix JSF and JSTL for the desired result. For example, use a JSF panelGrid and the JSTL forEach tag:

<h:panelGrid columns="6">
  <c:forEach var="photo" items="${album.photos}">
    <h:panelGrid columns="1">
      <h:graphicImage url="#{photo.url}"/>
      <h:outputText value="#{photo.title}"/>
      ...
    </h:panelGrid>

  </c:forEach>
</h:panelGrid>

But JSF and JSTL don't like each other, and such intermixing is not supported. I don't know all of the technical reasons why this doesn't work.

Another possible solution would be to pick up a third-party component library that had what I needed. Since free is my only option, I have looked into MyFaces Components (AKA Tomahawk) in the past. However, I was not able to get it to work with the specific JSF-portlet bridge, JSF implementation (the RI), and portlet container I was already bought into. Of course, I never really looked into whether MyFaces Components had the component I needed anyway.

Alas, the app is being written with plain old JSP + JSTL
Comments:

I'm doing the some basic idea,a cell with a couple of UI elements in it. You said you're falling back to JSP & JSTL. Do you have an example? Thanks...

Posted by stever on December 10, 2006 at 04:19 PM PST #

Post a Comment:
  • HTML Syntax: NOT allowed