dev@javaserverfaces.java.net

Re: DataTable components

From: Raymond DeCampo <ray_at_decampo.org>
Date: Thu, 27 May 2010 11:29:03 -0400

On Thu, May 27, 2010 at 9:17 AM, Drayton Brown <draytonbrown_at_gmail.com>wrote:

> Hi all
>
> Thanks for the response, Raymond!
>
> On 27 May 2010 05:30, Raymond DeCampo <ray_at_decampo.org> wrote:
>
>> On Wed, May 26, 2010 at 8:05 AM, Drayton Brown <draytonbrown_at_gmail.com>wrote:
>>
>>> 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?
>>>
>>
>> I'm speculating here, but the answer is almost certainly yes as the
>> dataTable component pre-dates the ability to make custom components by
>> composition, which was introduced in JSF 2.0.
>>
>> For my money, the way that dataTable is implemented/designed is a natural
>> outgrowth of the way tables are specified in HTML.
>>
>
> I'm not so sure of this since HTML makes use of table rows (<tr>), and
> cells (<td>) to specify a table. There is no column tag for a table in HTML.
>
>
>>
>>> 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 imagine the answer here is that there is no perceived need for it. I'm
>> not seeing the connection between such functionality and clickable rows.
>> Furthermore you could write your own implementation of DataModel which might
>> get you what you need, but I'm not really sure what that is, so maybe not.
>>
>>
> The connection is that I believe the reason why the data table was
> implemented using a columns approach is because having only a foreach
> component, which returned single items off the list, meant that the people
> implementing the data table could only get at the data a column entry at a
> time.
>

The dataTable implementation is all done in Java. It is in no way
restricted by the foreach tag. (Note that foreach is NOT a JSF component;
when using JSPs it is a JSP tag from JSTL and when using Facelets it is a
Facelets tag.) The table implementation iterates over the data in the table
(i.e. the rows) and then will iterate over the columns for whatever task it
is doing (e.g. encode, decode, validation, etc.).


>
> If we had an alternative to the foreach component that could return a
> subset of data from the list at a time (ie a rows' worth of data) then we
> could implement a data table by defining what a row looks like (and then
> what each cell in the row would look like, if we wanted to get that
> detailed).
>

You define what a row looks like by defining the columns. The dataTable
assumes you want each row to basically be the same.

If you have a list of data (essentially rows) and a list of columns, how is
restricting either to a subset going to get you what you want? These are
two independent lists.


> This means that we would have a row component where we could add event
> listeners like the 'onClick' event. Also this would more closely match the
> HTML approach to defining tables, which is more intuitive and is better from
> a logical layout point of view.
>

Every server-side implementation of a table I have ever seen iterates over
the data to create rows in the same manner as the dataTable. The real issue
you have with the dataTable component is the lack of control over the
outputted <tr> tags.


>
> Currently there is no way to specify an 'onClick' event for a row, instead
> one has to embed a component which can process an action in the table and
> then use the action method with the DataModel to access the current row.
> I find this messy and non intuitive since it adds extra components and
> forces the user to think in terms of columns instead of the natural approach
> of rows.
>
>
So why don't you define an onClick in the <tr> in TableRow.xhtml?