Changes for page Development-WO Component-Binding Synchronization
Last modified by Pascal Robert on 2010/09/19 10:29
From version 3.1
edited by Quinton Dolan
on 2007/07/12 20:04
on 2007/07/12 20:04
Change comment:
There is no comment for this version
To version 2.1
edited by smmccraw
on 2007/07/08 09:46
on 2007/07/08 09:46
Change comment:
There is no comment for this version
Summary
-
Page properties (2 modified, 0 added, 0 removed)
Details
- Page properties
-
- Author
-
... ... @@ -1,1 +1,1 @@ 1 -XWiki. qdolan1 +XWiki.smmccraw - Content
-
... ... @@ -2,52 +2,59 @@ 2 2 3 3 When you create a subclass of WOComponent, the default configuration is to have all of your bindings automatically synchronized. Binding synchronization is the process of getting and setting parent and chldren .wod file bindings during the request-response loop. While binding synchronization is very convenient, the one downside is that your binding get and set methods can be called multiple times (as many as six) during the request-response loop. As a result, you should be careful about potential performance problems inside of get and set methods. If you would rather avoid the potential performance issues, it is possible to disable automatic binding synchronization in your component by simply overriding the synchronizesVariablesWithBindings method to return false as in the below example: 4 4 5 -{{ code}}5 +{{panel}} 6 6 7 -public boolean synchronizesVariablesWithBindings() { 8 - return false; 9 -} 7 + public boolean synchronizesVariablesWithBindings() { 8 + return false; 9 + } 10 10 11 -{{/ code}}11 +{{/panel}} 12 12 13 -If synchronizesVariablesWithBindings is false, you will use the valueForBinding(bind ingName) and setValueForBinding(value, bindingName) methods to get and set the binding value manually.13 +If synchronizesVariablesWithBindings is false, you will use the valueForBinding(bindngName) and setValueForBinding(value, bindingName) methods to get and set the binding value manually. 14 14 15 15 == WOComponentContent == 16 16 17 -Because of the way WOComponentContent works, binding is often "backwards" from your intu ition (often it ends up that your wrapper pushes its title value into your page instead of the other way around). One way to make your template wrapper component behave the way you expect is to turn off automatic binding synchronization:17 +Because of the way WOComponentContent works, binding is often "backwards" from your intution (often it ends up that your wrapper pushes its title value into your page instead of the other way around). One way to make your template wrapper component behave the way you expect is to turn off automatic binding synchronization: 18 18 19 -{{ code}}19 +{{panel}} 20 20 21 -public boolean synchronizesVariablesWithBindings() { 22 - return false; 23 -} 21 + public boolean synchronizesVariablesWithBindings() { 22 + return false; 23 + } 24 24 25 -public String pageTitle() { 26 - return (String)valueForBinding("pageTitle"); 27 -} 25 +{{/panel}} 28 28 29 - {{/code}}27 + public String pageTitle() { 30 30 29 +{{panel}} 30 + 31 + return (String)valueForBinding("pageTitle"); 32 + } 33 + 34 +{{/panel}} 35 + 31 31 === Kieran Kelleher === 32 32 33 33 Have a look at WOComponent API valueForBinding and setValueForBinding methods. In your subcomponent, you can define the API (jigsaw icon in WOBuilder. Use lazy initialization to pull bindings on demand. Subcomponents in general pull from parent and push into parent through bindings. Here is an example of a simple manual pull and push of a 'customer' binding: 34 34 35 -{{ code}}40 +{{panel}} 36 36 37 -public CTCustomer customer() { 38 - if (customer == null) { 39 - customer = (CTCustomer)valueForBinding("customer"); 42 + public CTCustomer customer() 43 + { 44 + if (customer == null) { 45 + customer = (CTCustomer)valueForBinding("customer"); 46 + } 47 + return customer; 40 40 } 41 - return customer; 42 -} 49 + 50 + public void setCustomer(CTCustomer newCustomer) 51 + { 52 + customer = newCustomer; 53 + setValueForBinding(customer,"customer"); 54 + } 43 43 44 -public void setCustomer(CTCustomer newCustomer) { 45 - customer = newCustomer; 46 - setValueForBinding(customer,"customer"); 47 -} 56 +{{/panel}} 48 48 49 -{{/code}} 50 - 51 51 Also look at synchronizeVariablesWithBindings to turn on manual binding synchronization (recommended to synchronize on demand rather than 6 times or so through the R-R loop) 52 52 53 53 === wojingo ===