Changes for page Development-WO Component-Code Template and WODs
Last modified by Pascal Robert on 2012/07/19 21:09
From version 3.1
edited by Quinton Dolan
on 2007/07/15 02:49
on 2007/07/15 02:49
Change comment:
There is no comment for this version
To version 5.1
edited by Quinton Dolan
on 2007/07/12 20:08
on 2007/07/12 20:08
Change comment:
There is no comment for this version
Summary
-
Page properties (1 modified, 0 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -90,10 +90,8 @@ 90 90 91 91 Moving along in the WOD file, inside of curly braces, you can provide a series of key/value pairs, each ending with a semicolon as a separator. The left hand side of the equals is the binding name. The binding name is resolved on a WOComponent by attempting to find a mutator method or field on your WOComponent class that matches one of the naming conventions: public void setValue(Xxx param), public void //setValue(Xxx param), public Xxx value, public Xxx //value (assuming the example above of a binding named "value"). So if your WOComponent had a setValue method, and automatic binding synchronization was enabled, the setValue method would called passing in the evaluated value of the right hand side of the binding. In the example above, the right hand side is "personName". If personName was actually in quotes in example above, it would be considered a string literal and would be equivalent to calling setValue("personName"). 92 92 93 -However, personName has no quotes, and is thus interpreted with Key-Value-Coding (KVC). Key-Value-Coding allows you to string together a series of accessor method calls or field references as a string that WebObjects will dynamically resolve using Java reflection. For instance, in the example above, personName would attempt to find any accessor or field named: ##public String getPersonName(), public String //getPersonName(), public String personName(), public String //personName(), public String personName, public String //personName//##//. So if your Java class had a##public String getPersonName()##method, the return value of that method would be passed into the##setValue(..)##method of your WOComponent. Where KVC gets more interesting is that you can construct a series of method calls.//93 +However, personName has no quotes, and is thus interpreted with Key-Value-Coding (KVC). Key-Value-Coding allows you to string together a series of accessor method calls or field references as a string that WebObjects will dynamically resolve using Java reflection. For instance, in the example above, personName would attempt to find any accessor or field named: public String getPersonName(), public String //getPersonName(), public String personName(), public String //personName(), public String personName, public String //personName. So if your Java class had a public String getPersonName() method, the return value of that method would be passed into the setValue(..) method of your WOComponent. Where KVC gets more interesting is that you can construct a series of method calls. For instance, instead of a person, imagine that your WOSession had a "public Person person()" method, which had a "public Address address()" method, which had a "public String zipCode()" method. Your WOD file binding could look like "value = session.person.address.zipCode;", which would bind the zipcode of the address of the person in your sesson to value. Even more interesting are the NSArray operations that Foundation provides. For instance, if your session had a "public NSArray purchaseAmounts()" that returned an array of BigDecimals, you could refer to the binding "value = session.purchaseAmounts.@sum", which would return the sum of the values of the array. There are several other Array operations available in the Foundation classes, and Project Wonder provides even more in its [[ERXArrayUtilities>>Programming__WebObjects-WOnder-ERXArrayUtilities]] class. For even more advanced KVC capabilities, read the [[WOOgnl>>Programming__WebObjects-Project WONDER-Frameworks-WOOgnl]] section of Project Wonder.// 94 94 95 -For instance, instead of a person, imagine that your WOSession had a ##public Person person()## method, which had a ##public Address address()## method, which had a ##public String zipCode()## method. Your WOD file binding could look like ##value = session.person.address.zipCode;##, which would bind the zipcode of the address of the person in your sesson to value. Even more interesting are the NSArray operations that Foundation provides. For instance, if your session had a ##public NSArray purchaseAmounts()## that returned an array of ##BigDecimal##-s, you could refer to the binding ##value = session.purchaseAmounts.@sum##, which would return the sum of the values of the array. There are several other Array operations available in the Foundation classes, and Project Wonder provides even more in its [[ERXArrayUtilities>>Programming__WebObjects-WOnder-ERXArrayUtilities]] class. For even more advanced KVC capabilities, read the [[WOOgnl>>Programming__WebObjects-Project WONDER-Frameworks-WOOgnl]] section of Project Wonder. 96 - 97 97 A single WOD entry can contain several binding declarations, and a WOD file can contain many entries. For example, here is an excerpt from a real WOD file: 98 98 99 99 {{code}}