Revision history [back]

click to hide/show revision 1
initial version

answered 2020-08-19 11:27:09 +0800

cor3000 gravatar image cor3000

ZK Team

This looks like the perfect place for either (1) a custom TreeNode class with your additional getters (getChecked(), getDisabled()) or a wrapper class for your SuoRightDTO objects.

In case you decide for (1) you could have a MyTreeNode<SuoRightDTO>.

Then the @load()-bindings for the disabled/checked flag simplify to:

...
checked="@load(each.checked)" 
disabled="@load(each.disabled)"/>

when updating those flags all you need is to notify the individual object properties, not the whole tree:

BindUtils.postNotifyChange(null, null, myTreeNode, "disabled");
BindUtils.postNotifyChange(null, null, myTreeNode, "checked");

When using a wrapper is quite similare but instead of extending a TreeNode you can use a TreeNode<DisableSelectable<SuoRightDTO>>. Looks slightly more complex but leverages composition over inheritance. Like this you isolate your specific UI behaviors into the DisableSelectable<T> wrapper class (you can have all sorts of decorating getters/setters there). This extra layer allows you to use ZK's TreeNode classes and your DTOs unchanged by adding functionality optimized for you UI.

This gives you far better control than, methods you previously implemented. (vm.selectedItem.suoRights.contains(each.data) and vm.isDisabled(each))

...
checked="@load(each.data.checked)" 
disabled="@load(each.data.disabled)"/>

This looks like the perfect place for either (1) a custom TreeNode class with your additional getters getters/setters (getChecked()get/setChecked(), getDisabled()get/setDisabled()) or a wrapper class for your SuoRightDTO objects.

In case you decide for (1) you could have a MyTreeNode<SuoRightDTO>.

Then the @load()-bindings for the disabled/checked flag simplify to:

...
checked="@load(each.checked)" 
disabled="@load(each.disabled)"/>

when updating those flags all you need is to notify the individual object properties, not the whole tree:

BindUtils.postNotifyChange(null, null, myTreeNode, "disabled");
BindUtils.postNotifyChange(null, null, myTreeNode, "checked");

When using a wrapper is quite similare but instead of extending a TreeNode you can use a TreeNode<DisableSelectable<SuoRightDTO>>. Looks slightly more complex but leverages composition over inheritance. Like this you isolate your specific UI behaviors into the DisableSelectable<T> wrapper class (you can have all sorts of decorating getters/setters there). This extra layer allows you to use ZK's TreeNode classes and your DTOs unchanged by adding functionality optimized for you UI.

This gives you far better control than, methods you previously implemented. (vm.selectedItem.suoRights.contains(each.data) and vm.isDisabled(each))

...
checked="@load(each.data.checked)" 
disabled="@load(each.data.disabled)"/>
Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More