asked
2014-11-18 15:07:02 +0800
Matze2 773 ● 7 Consider a typical page with toolbarbuttons and a listbox. The "disabled" state of the toolbarbuttons depends on listbox selection.
Up to now I always bound selectedItems to a view model property so we have the following ZUL fragment:
<toolbarbutton ... disabled="@load(vm.action1Disabled)" onClick="@command('action1')"/>
...
<listbox ... model="@load(vm.listModel)" selectedItems="@bind(vm.selectedEntries)">
...
</listbox>
The "disabled" state was recalculated when the selection changes using @DependsOn annotation on the property:
@DependsOn("selectedEntries")
public boolean isAction1Disabled() {
// Compute state from selectedEntries and other data
}
This is how we did it up to now.
On the other hand we use ListModelList as listbox model and this also keeps the selection state.
So I wonder why I should maintain this state twice: once in ViewModel and once in listbox model. Just to be able to create property dependency on selectedEntries?
Does anybody know an elegant (MVVM) way to notify the change of selection-dependent properties just with the ListModelList selection and without having an explicit selection binding?
E.g. if the ListModelList selection change would be notified to the binder the following annotation could work:
@DependsOn("listModel.selection")
public boolean isAction1Disabled() {
// Compute state from selectedEntries and other data
}