Where the whole is greater than the sum of its parts
Since all components use JSP 2.0 tag files for their implementations, it is possible to easily create components which are composed of smaller ones. Thus, a composite can embed functionality already provided by (usually, more than one) other components, and add value by enabling reuse, since a composite now becomes a first-class component in its own right, defining the dialog management across its children, the public data model that gets returned etc.
- Example:
<rdc:mortgage id="myMortgage" />
- Where composition comes in
The guts of the mortgage composite contains this:
<rdc:group id="mortgageGroup" strategy="org.apache.taglibs.rdc.dm.SimpleDirectedDialog"> <rdc:mortgageType id="myMortgageType" ... /> <rdc:percent id="myPercentageDownpayment" ... /> </rdc:group>
where ... stands for other tag attributes not relevant to this discussion.
- Interpretation
Collect mortgage information, which due to the composition, means, collect a mortgage type and a percentage down payment (with constraints as specified by tag attributes), in that order.
Composites can contain other composites, so it is possible to recursively encapsulate larger bits of interaction within a single composite. The design decision regarding the optimum size of a component depends on factors such as how composition affects configurability, how much reuse across JSPs / applications is expected if further composition is pursued etc.