This discussion is archived
2 Replies Latest reply: Jun 26, 2012 2:07 AM by 937034 RSS

Elegant way to refresh List View and Form after deleting an element

937034 Newbie
Currently Being Moderated
Hi there,

given a task flow view, and a data-bound List View as well as a Form on it.
After selecting an item in the List View, it can be deleted from the underlying data base using a command button (an "onDelete" method is called by the button).

The UI is not automatically refreshing once the element has been removed. One possibility is to add a task flow case starting and ending at the concerned view and calling it in the "action" of the delete button. It works - both List View and Form then get refreshed -, but probably isn't good design. What could be a more elegant way?
  • 1. Re: Elegant way to refresh List View and Form after deleting an element
    DenisT Explorer
    Currently Being Moderated
    When you change the rows in a collection and want to have those changes reflected in data change events, you need to fire "provide change events". All of this is implemented in the HR example.

    You add the this line as a member of your class:

    private transient ProviderChangeSupport providerChangeSupport = new ProviderChangeSupport(this);

    And implement these two functions:

    public void addProviderChangeListener(ProviderChangeListener l) {
    providerChangeSupport.addProviderChangeListener(l);
    }

    public void removeProviderChangeListener(ProviderChangeListener l) {
    providerChangeSupport.removeProviderChangeListener(l);
    }

    And then call one of the following functions:

    // Call this after removing an element from the collection
    // Param1: collection name, Param2: key of that item
    providerChangeSupport.fireProviderDelete("employees", e.getKey());

    // Call this after adding an element to the collection
    // Param1: collection name, Param2: key of that item, Param3: object representing the new element
    providerChangeSupport.fireProviderCreate("employees", editEmployee.getKey(), editEmployee);

    // Call this when you want to completely refresh the list without doing each add/delete individually
    // Param1: collection name
    providerChangeSupport.fireProviderRefresh("employees");

    Note that if you are deleting, you need to change the current row to some new row. Typically this would be the previous row.
  • 2. Re: Elegant way to refresh List View and Form after deleting an element
    937034 Newbie
    Currently Being Moderated
    Have been trying around and for a Mobile List View element, it basically seems to work - I used the last method call, to refresh the list altogether.
    Following observations:
    - Refresh of list view does not work when the last (bottom) element in the list is selected and deleted. In this case, after the delete command, the list appears unchanged (deletion does takes place in the SQLite DB though, as it should). When hitting delete for the (now "phantom") list element a second time, an error message ("Error: undefined") pops up.
    - Once only two items are remaining in the list, and the first (top list entry) of these is selected and then deleted, the refresh empties the list altogether (both elements removed; in the SQLite DB however, like before, only the previously selected is deleted, as intended)
    - In the UI, there is a form adjacent to the List View; the form shows the details for a selected list item (similar to the HRDemo). The form is using the same data control as the list. Its content, however, is not refreshed along with the list's. I guess some additional code is required for it? The HRDemo does not have delete or insert commands, for a direct comparison.
    - The HRDemo app is using propertyChangeSupport; what is the difference between this and providerChangeSupport?

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points