Type Coercion is the conversion of one type of object to a new object of a different type with similar content. Tapestry frequently must coerce objects from one type to another. A common example is the coercion of a string into an integer or a double.
See Type Coercer Service for the list of build-in coercions.
Parameter Type Coercions
Tapestry automatically handles type coercions for component parameters.
Type coercions occur when a value passed into a parameter (as bound in a template or in an annotation) does not match the type of the parameter.
For example, consider the Count component:
Here, the type of all three parameters is
However, it is likely that the component will be used as so:
A bare whole number is interpreted by the prop binding prefix as a
long. So this is the long value 3.
Tapestry will automatically coerce the bound value, a
long, to the parameter's type,
int. This may be a lossy coercion (if the
long represents a number larger than can be stored in an
Main Article: TypeCoercer Service
The TypeCoercer service is responsible for this type coercion. This service is part of the tapestry-ioc module. The service is quite extensible, allowing for new types and coercions to be added easily. The TapestryModule contributes a few additional coercions into the TypeCoercer service.