0

Can't disable checkbox parent

asked 2020-08-18 18:03:34 +0800

AnnaU gravatar image AnnaU
3 1

updated 2020-08-19 11:11:10 +0800

cor3000 gravatar image cor3000
5399 2 7
ZK Team

I have a tree (DefaultTreeModel<treenode<suorightdto>>) of checkboxes:

<tabpanel width="100%" height="100%" style="border: 0; padding: 0;" vflex="1" hflex="1">
  <tree id="rightTree" model="@load(vm.adminModTree)" vflex="1"  >
    <template name="model">
      <treeitem open="true">
        <treerow>
          <treecell>
            <checkbox label="${each.data.name}"
                onCheck="@command('checkRight', node=each, 
                                   checked=self.isChecked())"
                checked="@load(vm.selectedItem.suoRights.contains(each.data))" 
                disabled="@load(vm.isDisabled(each))"/> 
          </treecell>
        </treerow>
      </treeitem>
    </template>
  </tree>
</tabpanel>

This is method "checkRight":

@Command("checkRight")
public void checkRight(@BindingParam("node") TreeNode<SuoRightDTO> node, @BindingParam("checked") boolean checked) {
    if (checked) {
       getSelectedItem().getSuoRights().add(node.getData());
        if(node.getParent()!=null){
            getSelectedItem().getSuoRights().add(node.getParent().getData());
            if(node.getParent().getParent()!=adminModTree.getRoot().getData()){
                getSelectedItem().getSuoRights().add(node.getParent().getParent().getData());
            }

            BindUtils.postNotifyChange(null, null, this, "adminModTree");
         }
    } else {
        getSelectedItem().getSuoRights().remove(node.getData());
    }
}

I need to disable a parent of a child that checked. Now it it's just checked without disable.

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

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

cor3000 gravatar image cor3000
5399 2 7
ZK Team

updated 2020-08-19 11:29:04 +0800

This looks like the perfect place for either (1) a custom TreeNode class with your additional getters/setters (get/setChecked(), 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)"/>
link publish delete flag offensive edit
Your answer
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
1 follower

RSS

Stats

Asked: 2020-08-18 18:03:34 +0800

Seen: 7 times

Last updated: Aug 19

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