Binding in Special Attribute"

From Documentation
Line 6: Line 6:
 
<!-- ZK Bind doesn't work on those special attributes. -->
 
<!-- ZK Bind doesn't work on those special attributes. -->
  
ZK Bind is a post-processing work on components after they are created. ZK Bind can control most attributes to change a component's status. But there are [[ZUML_Reference/ZUML/Attributes| 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 <tt>if</tt> and <tt>forEach</tt>. Therefore, binding on these special attributes takes no effect on components.
+
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 [[ZUML_Reference/ZUML/Attributes| 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 <tt>if</tt> and <tt>forEach</tt>. 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" =
 
= The "if" Versus the "visible" =

Revision as of 03:33, 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 an user's permission is unchanged when he visits the page and only the user with "admin" permission can see the "Delete" button. Then we can write a binding on if as follows:

	<!-- "if" usage  -->
	<button label="Edit" />	
	<button label="Delete" if="@load(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