Binding in Special Attribute"

From Documentation
Line 24: Line 24:
 
</source>
 
</source>
  
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.
+
The first one (line 2) is a wrong usage. The button will never be created.
 
 
  
 
<!-- binding in "visible" and "disable" instead of "if" -->
 
<!-- binding in "visible" and "disable" instead of "if" -->

Revision as of 03:56, 15 March 2013

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)" />

The first one (line 2) is a wrong usage. The button will never be created.


  • if = ${vm.currentUser.admin}

The "forEach" Versus Children Binding

  • forEach -> children binding