dev@javaserverfaces.java.net

DataTable components

From: Drayton Brown <draytonbrown_at_gmail.com>
Date: Wed, 26 May 2010 13:05:15 +0100

Hello

I was hoping someone on these mailing lists could let me know a couple of
things.

Firstly a little background. I'm new to JSF and one of the main components I
use is the DataTable.
While using this table I've found that there are a couple of features that
are lacking and only available in 3rd party component libraries.

The one that I would like to talk about it the ability to have clickable
rows in a datable.
I've looked into various workarounds for this, but it seems that if you want
a clickable row in a datatable without using 3rd party libraries the only
solution is to add an extra column to your table and embed command buttons
into the column for the action you would like to perform. Although this is a
workable solution, it would be better to have a clickable row.

One of the ways I tried to overcome this problem is that I tried to create
my own composite datatable component. This is where I discovered what I
believe to be the reason for all the problems. It seems to me that at some
point the decision was make to define a datatable by specifying the columns
the table has. This was done to simplify the iteration over the datatable
dataset (usually a simple list). By specifying the columns a developer would
be implicitly defining the size of a row in the dataset, allowing the
component to break the dataset into rows and display them in the appropriate
columns. This turns out to be the simplest way to do this given the already
created components (ie. the Foreach core component)

The problem I find with this is that data in tables is usually accessed as
rows. However when trying to implement my own datatable composite component
using rows, I bumped into the problem I'm sure the resulted in the current
solution in the first place. The only iterator we have is the foreach core
component and it does not return more than a single item off the list at a
time. That means that the following is not possible, as there is no iterator
that returns a subset of a dataset:

DataTable.xhtml
<cc:implementation>
        <table>
            <my:TableBody id="#{cc.attrs.id}_TB" rows="#{cc.attrs.rows}"
columns="#{cc.attrs.columns}"/>
        </table>
</cc:implementation>

Where #{cc.attrs.rows} is the datatable list data and #{cc.attrs.columns} is
the number of columns in the table

TableBody.xhtml
<cc:implementation>
        <tbody id="#{cc.attrs.id}">
                <!-- iterator that can return a subset of the datalist -->
<my:TableRow id="#{cc.attrs.id}_TR_#{state.count}" value="#{row}"/>
<!-- iterator terminator -->
        </tbody>
</cc:implementation>

TableRow.xhtml
<cc:implementation>
        <tr>
            <c:forEach items="#{cc.attrs.value}" var="cell"
varStatus="state">
                <my:TableCell id="#{cc.attrs.id}_TC_#{state.count}"
value="#{cell}"/>
            </c:forEach>
        </tr>
</cc:implementation>

So I guess the sort of information I'm looking for is
1) Are there any other reasons for defining a datatable using columns
besides the limitations on the foreach core component?
2) If the answer the question 1 is no, then were there any reasons for not
developing a new data iterator which returned subsets of data?

I've checked out the JSF code from SVN, and I've been looking at the foreach
component code (although I cannot get it to compile yet).
I was thinking of implementing a ForEachSet component, but I do not want to
get into it if there are other reasons for not doing it.

Thanks for any help in advance

Regards
Drayton