Table getValue() after removing row(s) should be zero

Hi all,

I’ve read a bunch of posts and can’t find this exact question. I think it’s a simple one, so this is probably an exercise in pointing me to a 5 year old answer…

I have a table using a SQLContainer data source that allows multi-select. The table has edit/delete buttons for whatever is selected, and the table’s value change listener calls a method to enable/disable the buttons:

    private void setButtonStates() {
        final int size = ((Set<RowId>) table.getValue()).size();
        // enable edit button if size is 1
        // enable delete button if size is at least 1
    }

My problem is in my listener for the delete button. It removes the proper item from the database, calls refresh() on the container, and then calls the setButtonStates() method above. The table renders properly (the item that should disappear disappears), but table.getValue still has a size of one so the buttons are wrong.

I guess this makes sense – the table renders its value after my code, before the request returns. But how can I fix my button states method? I know I can just disable the buttons after a delete, but it seems like there should be a more generic way of handling this. I can’t figure out if there’s anything in the container at this point that tells me what’s selected (which should be nothing), but I also think the container shouldn’t know about that level of things so it makes sense.

Any ideas besides a method specifically for deletes that disable the buttons?

Thanks,
Bobby

Hi ,

Instead of table.getValue() .size() ,i think you should try
table.size()
here .

Thanks, but that gives me the number of items in the table. I need the number of items that are currently selected in order to properly enable/disable the buttons underneath.

Cheers,
Bobby