Binding in Special Attribute

From Documentation

location:

  • MVVM/Advanced/Parameter
  • MVVM/Advanced/Binding in Special Attributes

Special Attribute Issue

ZK Bind is a post-processing work on components after they are created and it can control most attributes to change a component's status. But there are some special attributes that ZK Bind can't work on them because those attributes' value are determined and fixed when components are created such as if and forEach. Therefore, binding on these special attributes takes no effect on components. But you may want the function that those special attributes provide, here we demonstrate alternives in MVVM approach.

The "if" Versus the "visible"

Assume that you want to show a "Delete" button only to a user who has administrative permission. We have several usage:

specialAttribte.zul

		<!-- wrong usage, no effect -->
		<button label="Delete " if="@load(vm.currentUser.admin)" />
		<!-- determined at the beginning -->
		<button label="Delete (EL)" if="${vm.currentUser.admin}" />
		<!-- can change during user interaction -->
		<button label="Delete (visible)" visible="@load(vm.currentUser.admin)" />
		<checkbox label="Is Admin" checked="@bind(vm.currentUser.admin)" />

On the page above, those users without "admin" permission can't see the "Delete" button. Even if you assign the user with "admin" permission through a command, the "Delete" will not appear. But if you visit the page again after assigning the user "admin" permission, the button will appear.


  • if = ${vm.currentUser.admin}

The "forEach" Versus Children Binding

  • forEach -> children binding