0

MVVM: can't get clearSelection() to work properly with Listbox

asked 2012-09-16 22:41:12 +0800

czynga gravatar image czynga
171

Hello,

I have this strange problem with clearing Listbox selection, it just doesn't work for me.

View:

<listbox model="@load(vm.tableDataModel)" selectedItems="@bind(vm.selectedTableItems)">
    ...
    <template name="model" var="tableItem">
        ...
    </template>
</listbox>

<button label="Dismiss" onClick="@command('dismissChanges')"></button>

ViewModel:

private Set<ShiftBean> selectedTableItems = new HashSet<ShiftBean>();
private ListModelList<ShiftBean> tableDataModel = new ListModelList<ShiftBean>();

public Set<ShiftBean> getSelectedTableItems() {
        return selectedTableItems;
    }

public void setSelectedTableItems(final Set<ShiftBean> items) {
        selectedTableItems = items;
    }

public ListModelList<ShiftBean> getTableDataModel() {
        return tableDataModel;
    }

@Command
public void dismissChanges() {
    if (!selectedTableItems.isEmpty()) {
        tableDataModel.clearSelection();
    } else {
        Clients.showNotification("empty");
    }
}

Now the important information:
if I leave my command like it is without any @NotifyChange then selection is visually cleared but the real data in selectedTableItems is not changed and the next tableDataModel update selection visually comes back.
But if I add this

@NotifyChange({"tableDataModel", "selectedTableItems"})
to my command then nothing happens at all, selection is not cleard visually and data set is not cleared either.

Any ideas, please?

delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest

answered 2012-09-17 04:55:14 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

Hi ,
Please update selectedTableItems = null and then add in the NotifyChange..and also you can change the position sometime position also effects.
@NotifyChange({"selectedTableItems", "tableDataModel"}).
Thanks

link publish delete flag offensive edit

answered 2012-09-18 01:13:36 +0800

czynga gravatar image czynga
171

updated 2012-09-18 01:14:38 +0800

Thank you sjoshi but it doesn't work. I've tried with different @NotifyChange order and tried with "selectedTableItems = null" with/without/before/after clearSelection and it still doesn't work...

link publish delete flag offensive edit

answered 2012-09-18 04:44:04 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

Can it possible for you to post ur code here so that i can test it in my environment.
thanks

link publish delete flag offensive edit

answered 2012-10-14 23:32:53 +0800

czynga gravatar image czynga
171

Problem solved. Default clearSelection() method still doesn't work for me but as a workaround I'm using

selectedTableItems = new HashSet<ShiftBean>();

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2012-09-16 22:41:12 +0800

Seen: 137 times

Last updated: Oct 14 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More