JSF - Add data to table

S

Steve

Are there any JSF table components (e.g., RichFaces, etc.) that allow you to add a new row directly to the table without having an
add button and a screen/subscreen to enter the additional data? For example, the RichFaces ScrollableDataTable and
ScrollabledataTable provide some of the functionality but I'm not sure if they allow new rows to be added within the table. If
possible, I'd prefer one that uses Ajax and has scroll bars and/or pagination.

Thanks.

Steve
 
A

Arved Sandstrom

Are there any JSF table components (e.g., RichFaces, etc.) that allow
you to add a new row directly to the table without having an add button
and a screen/subscreen to enter the additional data? For example, the
RichFaces ScrollableDataTable and ScrollabledataTable provide some of
the functionality but I'm not sure if they allow new rows to be added
within the table. If possible, I'd prefer one that uses Ajax and has
scroll bars and/or pagination.

Thanks.

Steve

Is your objection to having an Add button or having a separate page for
entering the new data, or both? Because if it's just about the separate
page, that's readily addressed.

I've seen some authors take the approach of using the same backing list,
and adding an editable new item to it when an "Add Something" button is
clicked...the new row uses enabled/input elements, and the other rows use
disabled/output elements (this keys off the fact that the new item has a
null ID - you haven't persisted it yet).

However, there's an even easier way to do it, which is to keep an
h:dataTable only for the display of existing items (the value of _this_
table is the backing list of already persisted/committed items), and have
a separate HTML table (not a dataTable) immediately after the h:dataTable
which has only one row: the new object. The getters and setters become
very simple - they just correspond to the fields of a single entity.

If you read some authors (for example http://balusc.blogspot.com/2006/06/
using-datatables.html#AddNewRowsToDatatable) they are potentially adding
more than one row at once, so a counter gets passed as a hidden form
value, for request-scoped managed beans. For a single row this is
unnecessary in approach #1. For my approach, with either a request or
session-scoped managed bean, you can set a boolean variable on the bean
that is used by a <c:if> to decide whether or not to show the "new row"
HTML table.

Visually and from a user functional standpoint both approaches are
identical. As I say, I consider my suggestion to be easier and cleaner.

AHS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,158
Latest member
Vinay_Kumar Nevatia
Top