Binding in Special Attribute"

From Documentation
Line 3: Line 3:
 
* MVVM/Advanced/Binding in Special Attributes
 
* MVVM/Advanced/Binding in Special Attributes
  
= Binding
+
= Special Attribute Issue =
 
<!-- ZK Bind doesn't work on those special attributes. -->
 
<!-- ZK Bind doesn't work on those special attributes. -->
  
When a ViewModel's property changes, ZK will re-load those corresponding bindings on attributes. Then this reloading usually causes a UI change because attributes control a component's status and behavior. This is the basic way we change an attribute's value in MVVM approach. But there are [[ZUML_Reference/ZUML/Attributes| some special attributes]] that we can't do so. ZK will not reload value of these special attributes after a component is created and their value is determined and fixed at creation phase. Therefore, we should bind these special attributes to those properties that will not change after component creation (or uses these attributes in the condition that don't care the changed properties).
+
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.
  
  

Revision as of 03:24, 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. ZK Bind 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.


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