Last modified by Pascal Robert on 2010/09/19 10:29

Hide last authors
Pascal Robert 4.1 1 == Overview ==
smmccraw 1.1 2
Pascal Robert 6.1 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:
smmccraw 1.1 4
Quinton Dolan 3.1 5 {{code}}
smmccraw 1.1 6
Quinton Dolan 3.1 7 public boolean synchronizesVariablesWithBindings() {
8 return false;
9 }
smmccraw 1.1 10
Quinton Dolan 3.1 11 {{/code}}
smmccraw 1.1 12
Quinton Dolan 3.1 13 If synchronizesVariablesWithBindings is false, you will use the valueForBinding(bindingName) and setValueForBinding(value, bindingName) methods to get and set the binding value manually.
smmccraw 1.1 14
Pascal Robert 4.1 15 == WOComponentContent ==
smmccraw 1.1 16
Pascal Robert 6.1 17 Because of the way WOComponentContent works, binding is often "backwards" from your intuition (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:
smmccraw 1.1 18
Quinton Dolan 3.1 19 {{code}}
smmccraw 1.1 20
Quinton Dolan 3.1 21 public boolean synchronizesVariablesWithBindings() {
22 return false;
23 }
smmccraw 1.1 24
Quinton Dolan 3.1 25 public String pageTitle() {
26 return (String)valueForBinding("pageTitle");
27 }
smmccraw 1.1 28
Quinton Dolan 3.1 29 {{/code}}
smmccraw 1.1 30
Pascal Robert 4.1 31 === Kieran Kelleher ===
smmccraw 1.1 32
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
Quinton Dolan 3.1 35 {{code}}
smmccraw 1.1 36
Quinton Dolan 3.1 37 public CTCustomer customer() {
38 if (customer == null) {
39 customer = (CTCustomer)valueForBinding("customer");
smmccraw 1.1 40 }
Quinton Dolan 3.1 41 return customer;
42 }
smmccraw 1.1 43
Quinton Dolan 3.1 44 public void setCustomer(CTCustomer newCustomer) {
45 customer = newCustomer;
46 setValueForBinding(customer,"customer");
47 }
smmccraw 1.1 48
Quinton Dolan 3.1 49 {{/code}}
50
smmccraw 1.1 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
Pascal Robert 4.1 53 === wojingo ===
smmccraw 1.1 54
Pascal Robert 4.1 55 If you use lazy initialization in your binding accessor methods as described above, you should also make the component
Pascal Robert 6.1 56 stateless. If you do not make the component stateless you will find that your component may display incorrect values when
57 used in a WORepetition. This situation occurs when the WORepetition's list is changed via a component action and null is returned. The existing nested component will be reused and the values in the original list will be displayed.
smmccraw 1.1 58
Pascal Robert 4.1 59 Make the component stateless and override its reset method, setting all instance variables to null. This will make the
Pascal Robert 6.1 60 component behave as expected.