form-dataeclipse-scout

Scout Eclipse table Form data number of rows


I encounter very strange behavior and I don't know if this is intentionally or it is a bug inside scout. (I could understand why this could be a feature, but then I need some work around...)

I have some table inside form. Let suppose that I have two columns Column A and Column B and I have two rows.

------------------------
| Column A  | Column B | 
------------------------
|  10       | 20       |
------------------------
|  30       | 40       |
------------------------

if I check on client last row like this :

getTField().getTable().getAColumn().getValue(getTField().getTable().getRowCount() -1) = 30

final TFormData formData = new TFormData();
this.exportFormData(formData);
formData.getTable().getAColumn(formData.getTable().getRowCount() - 1) = 30

and this is ok. Now I update last row and delete first one so now it looks like this :

------------------------
| Column A  | Column B | 
------------------------
|  60       | 40       |
------------------------

now If I try same as before :

// row count = 1
getTField().getTable().getAColumn().getValue(getTField().getTable().getRowCount() -1) = 60 

final TFormData formData = new TFormData();
this.exportFormData(formData);
// row count = 2
formData.getTable().getAColumn(formData.getTable().getRowCount() - 1) = 30
formData.getTable().getAColumn(formData.getTable().getRowCount() - 2) = 60

like previous (deleted) row stays inside form data.

I understand that just update already created rows to current value is quicker then replace all rows but shouldn't getRowCount return right number ?


Solution

  • If I understand your question correctly, you want to know why deleted rows stay in the table and how this affects the row count.

    First: Eclipse Scout has two ways that it can handle deleted rows:

    1. The "recycling bin mode" in which deleted rows just change their row state (ITableRow.getRowState()) to ITableRow.STATUS_DELETED. You can use this to send these all rows of the table to a service and easily see which rows were deleted and persist these changes. (The same way as you can see which rows were inserted/changed). This mode is typically used if your user adds/modifies/deletes multiple rows and the changes are persisted only on a 'save action' (OK button or similar).
    2. The "immediate deletion mode" in which rows are discarded immediately when they are deleted. You cannot retrieve these discarded rows from the scout model again at a later time. Typically used when you operate in a table page when any changes of the user are to be applied immediately.

    You can switch between those two modes by overriding AbstractTable.getConfiguredAutoDiscardOnDelete(). The default return value is falsewhich is "mode 1", truewould put you in "mode 2" and instruct scout to immediately discard any row that is deleted.

    To address the row count/index part of your question:

    If you delete rows and do not discard them (mode 1), you will need to account for these rows that are not visible to the user. The row count will include those deleted invisible rows!

    Source: Eclipse Scout Concept Wiki: Table - Delete a row from the table