views:

47

answers:

1

Just wondering if it is possibly to dynamically add elements (in AJAX fashion) to a form using h:dataTable without always submitting the current contents? Normally one has to always send the full contents of the datatable, because the whole datatable is re-rendered. If the datatable gets big (say, 100 rows) this can radically slow down the page, as each row always gets posted.

Doing this with raw JS this is not a problem, but can it be avoided with JSF? Of course if we don't send all the row data with the AJAX request, it remains lightweight, but we will lose all the changes made to the form.

+1  A: 

PrimeFaces has a datatable with ability to add rows without always submitting the current content.

You can see datatable ajax example.

Follow the instructions of getting started.

Odelya
True, that's one way to do it (to keep the edit form separate from the actual listing). I don't, however, see what extra benefits PrimeFaces brings in this case? The same could be achieved with stock JSF 2.0. Also, what I am actually looking for is to have the datatable itself work as a form, so each row would have one or more input fields (this makes a more convenient UI for editing long lists quickly).
Tuukka Mustonen
if you look in PrimeFaces datatable, you can see that they have an editable table as well.
Odelya
Yeah, but that's still not the same. That one submits one row at a time - you have to click specific save button for each row. I want all the lines editable by default. Sorry, I should've been more specific in my question. Anyway, maybe the right workaround here would be to auto-submit when user jumps from one row to another (if that row was modified). Then there would be no need to submit all the rows when adding new, as changes from all the rows would be already saved to the server. This would still make some excess traffic (lots of AJAX requests at least), but could be a viable solution.
Tuukka Mustonen