Author: buildbot
Date: Mon Dec 15 14:20:11 2014
New Revision: 932838
Log:
Production update by buildbot for tapestry
Added:
websites/production/tapestry/content/parameter-type-coercion.html
websites/production/tapestry/content/type-coercion.data/
websites/production/tapestry/content/type-coercion.data/type-coercer.png
(with props)
Modified:
websites/production/tapestry/content/cache/main.pageCache
websites/production/tapestry/content/component-parameters.html
websites/production/tapestry/content/redirects.html
websites/production/tapestry/content/type-coercion.html
websites/production/tapestry/content/typecoercer-service.html
Modified: websites/production/tapestry/content/cache/main.pageCache
==============================================================================
Binary files - no diff available.
Modified: websites/production/tapestry/content/component-parameters.html
==============================================================================
--- websites/production/tapestry/content/component-parameters.html (original)
+++ websites/production/tapestry/content/component-parameters.html Mon Dec 15
14:20:11 2014
@@ -66,7 +66,8 @@
</div>
<div id="content">
-<div id="ConfluenceContent"><div class="navmenu" style="float:right;
background:#eee; margin:3px; padding:3px">
+<div id="ConfluenceContent"><div class="navmenu" style="float:right;
background:white; margin:3px; padding:3px">
+<div class="panel" style="border-width: 1px;"><div class="panelContent">
<h3>Related Articles</h3>
<ul class="content-by-label"><li>
<div>
@@ -150,19 +151,22 @@
</div>
</li></ul>
-</div><h1 id="ComponentParameters-ComponentParameters">Component
Parameters</h1><p><style type="text/css">/*<![CDATA[*/
-div.rbtoc1418617260252 {padding: 0px;}
-div.rbtoc1418617260252 ul {list-style: disc;margin-left: 0px;}
-div.rbtoc1418617260252 li {margin-left: 0px;padding-left: 0px;}
+</div></div>
-/*]]>*/</style></p><div class="toc-macro rbtoc1418617260252">
+<p><strong>Contents</strong></p>
+<style type="text/css">/*<![CDATA[*/
+div.rbtoc1418653179986 {padding: 0px;}
+div.rbtoc1418653179986 ul {list-style: disc;margin-left: 0px;}
+div.rbtoc1418653179986 li {margin-left: 0px;padding-left: 0px;}
+
+/*]]>*/</style><div class="toc-macro rbtoc1418653179986">
<ul class="toc-indentation"><li>Related Articles</li></ul>
-<ul><li><a shape="rect"
href="#ComponentParameters-ComponentParameters">Component
Parameters</a></li><li><a shape="rect"
href="#ComponentParameters-ParameterBindings">Parameter Bindings</a></li><li><a
shape="rect" href="#ComponentParameters-BindingExpressions">Binding
Expressions</a>
+<ul><li><a shape="rect"
href="#ComponentParameters-ParameterBindings">Parameter Bindings</a></li><li><a
shape="rect" href="#ComponentParameters-BindingExpressions">Binding
Expressions</a>
<ul class="toc-indentation"><li><a shape="rect"
href="#ComponentParameters-RenderVariables:Bindings">Render Variables:
Bindings</a></li><li><a shape="rect"
href="#ComponentParameters-Property:Bindings">Property: Bindings</a></li><li><a
shape="rect" href="#ComponentParameters-Validate:Bindings">Validate:
Bindings</a></li><li><a shape="rect"
href="#ComponentParameters-Translate:Bindings">Translate:
Bindings</a></li><li><a shape="rect"
href="#ComponentParameters-Asset:Bindings">Asset: Bindings</a></li><li><a
shape="rect" href="#ComponentParameters-Context:Bindings">Context:
Bindings</a></li></ul>
</li><li><a shape="rect"
href="#ComponentParameters-@Parameterannotation">@Parameter annotation</a>
<ul class="toc-indentation"><li><a shape="rect"
href="#ComponentParameters-RequiredParameters">Required
Parameters</a></li><li><a shape="rect"
href="#ComponentParameters-OptionalParameters">Optional
Parameters</a></li><li><a shape="rect"
href="#ComponentParameters-ParameterBindingDefaults">Parameter Binding
Defaults</a></li><li><a shape="rect"
href="#ComponentParameters-ParameterCaching">Parameter Caching</a></li></ul>
</li><li><a shape="rect"
href="#ComponentParameters-Don'tusethe${...}syntax!">Don't use the ${...}
syntax!</a></li><li><a shape="rect"
href="#ComponentParameters-InformalParameters">Informal
Parameters</a></li><li><a shape="rect"
href="#ComponentParameters-ParametersAreBi-Directional">Parameters Are
Bi-Directional</a></li><li><a shape="rect"
href="#ComponentParameters-InheritedParameterBindings">Inherited Parameter
Bindings</a></li><li><a shape="rect"
href="#ComponentParameters-ComputedParameterBindingDefaults">Computed Parameter
Binding Defaults</a></li><li><a shape="rect"
href="#ComponentParameters-UnboundParameters">Unbound Parameters</a></li><li><a
shape="rect" href="#ComponentParameters-ParameterTypeCoercion">Parameter Type
Coercion</a></li><li><a shape="rect"
href="#ComponentParameters-ParameterNames">Parameter Names</a></li><li><a
shape="rect" href="#ComponentParameters-DeterminingifBound">Determining if
Bound</a></li><li><a shape="rect" href="#ComponentParameters-PublishingP
arameters">Publishing Parameters</a></li></ul>
-</div><p><strong>Component parameters</strong> are the primary means for a
component instance and its container to communicate with each other. Parameters
are used to <em>configure</em> component instances.</p><p>In the following
example, <code>page</code> is a parameter of the <code>pagelink</code>
component. The page parameter tells the pagelink component which page to go to
when the user clicks on the rendered hyperlink:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
+</div></div><p><strong>Component parameters</strong> are the primary means for
a component instance and its container to communicate with each other.
Parameters are used to <em>configure</em> component instances.</p><p>In the
following example, <code>page</code> is a parameter of the
<code>pagelink</code> component. The page parameter tells the pagelink
component which page to go to when the user clicks on the rendered
hyperlink:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
<script class="theme: Default; brush: xml; gutter: false"
type="syntaxhighlighter"><![CDATA[<html
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd">
<t:pagelink page="Index">Go Home</t:pagelink>
</html>
@@ -226,7 +230,7 @@ public class Count
</p>
</html>
]]></script>
-</div></div><p>The end attribute is used to <em>bind</em> the end parameter of
the Count component. Here, it is being bound to the string value "3", which is
automatically <a shape="rect" href="type-coercion.html">coerced</a> by Tapestry
into the int value, 3.</p><p>Any number of parameters may be bound this
way.</p><p>Component parameters may also be bound using the @<a shape="rect"
class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/annotations/Component.html">Component</a>
annotation inside the component class. (Where conflicts occur, the parameters
bound using the Component annotation will take precedence over parameter
bindings in the template.)</p><p><span class="confluence-anchor-link"
id="ComponentParameters-binding-expressions"></span></p><h1
id="ComponentParameters-BindingExpressions">Binding Expressions</h1><p>The
value inside the template, "3" in the previous example, is a <em>binding
expression</em>.</p><p>By placing a prefix in f
ront of the value, you can change how Tapestry interprets the remainder of the
expression (the part after the colon):</p><div class="table-wrap"><table
class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1"
class="confluenceTh"><p><strong>Prefix</strong></p></th><th colspan="1"
rowspan="1"
class="confluenceTh"><p><strong>Description</strong></p></th></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p>asset:</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>The relative path to an asset file (which
must exist)</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>block:</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>The id of a block within the
template</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>component:</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>The id of another component within the same
template</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>context:</p></td><t
d colspan="1" rowspan="1" class="confluenceTd"><p>Context asset: path from
context root</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>literal:</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>A literal string</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p>nullfieldstrategy:</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Used to locate a pre-defined <a
shape="rect" class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/NullFieldStrategy.html">NullFieldStrategy</a></p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p>message:</p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Retrieves a string from the
component's <a shape="rect"
href="#ComponentParameters-localization.html">message
catalog</a></p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>prop:</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>A <a shape="rect" href="prop
erty-expressions.html">property expression</a> to read or
update</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>symbol:</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Used to read one of your <a shape="rect"
href="symbols.html">symbols</a></p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>translate:</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>The name of a configured
translator</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>validate:</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>A <em>validator specification</em> used to create some
number of field validators</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>var:</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Allows a render variable of the component to be read or
updated</p></td></tr></tbody></table></div><p>Most of these binding prefixes
allow parameters to be bound to read-only values; for inst
ance a parameter bound to "message:some-key" will see the message for
"some-key" from its container's message catalog in the field. If the component
tries to update the parameter (by setting the value of the field), a runtime
exception will be thrown to indicate that the value is read-only.</p><p>Only
prop: and var: binding prefixes are updateable (but you must <em>not</em> use
the ${..} syntax here; see the <a shape="rect"
href="#ComponentParameters-dontUseSyntax">warning below</a>).</p><p>Each
parameter has a default prefix, defined by the component, that is used when the
prefix is not provided. The most common are "literal:" and "prop:".</p><p>A
<em>special prefix</em>, "inherit:", is used to support <a shape="rect"
href="#ComponentParameters-InheritedParameterBindings">Inherited Parameter
Bindings</a>.</p><h3 id="ComponentParameters-RenderVariables:Bindings">Render
Variables: Bindings</h3><p>Components can have any number of <em>render
variables</em>. Render variables are named
values with no specific type (they are ultimately stored in a Map). Render
variables are useful for holding simple values, such as loop indices, that need
to be passed from one component to another.</p><p>For example, the following
template code:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
+</div></div><p>The end attribute is used to <em>bind</em> the end parameter of
the Count component. Here, it is being bound to the string value "3", which is
automatically <a shape="rect" href="parameter-type-coercion.html">coerced</a>
by Tapestry into the int value, 3.</p><p>Any number of parameters may be bound
this way.</p><p>Component parameters may also be bound using the @<a
shape="rect" class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/annotations/Component.html">Component</a>
annotation inside the component class. (Where conflicts occur, the parameters
bound using the Component annotation will take precedence over parameter
bindings in the template.)</p><p><span class="confluence-anchor-link"
id="ComponentParameters-binding-expressions"></span></p><h1
id="ComponentParameters-BindingExpressions">Binding Expressions</h1><p>The
value inside the template, "3" in the previous example, is a <em>binding
expression</em>.</p><p>By placing a p
refix in front of the value, you can change how Tapestry interprets the
remainder of the expression (the part after the colon):</p><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh"><p><strong>Prefix</strong></p></th><th
colspan="1" rowspan="1"
class="confluenceTh"><p><strong>Description</strong></p></th></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p>asset:</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>The relative path to an asset file (which
must exist)</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>block:</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>The id of a block within the
template</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>component:</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>The id of another component within the same
template</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>context:<
/p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Context asset:
path from context root</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>literal:</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>A literal string</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p>nullfieldstrategy:</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Used to locate a pre-defined <a
shape="rect" class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/NullFieldStrategy.html">NullFieldStrategy</a></p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p>message:</p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Retrieves a string from the
component's <a shape="rect"
href="#ComponentParameters-localization.html">message
catalog</a></p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>prop:</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>A <a shape="rect"
href="property-expressions.html">property expression</a> to read or
update</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>symbol:</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Used to read one of your <a shape="rect"
href="symbols.html">symbols</a></p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>translate:</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>The name of a configured
translator</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>validate:</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>A <em>validator specification</em> used to create some
number of field validators</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p>var:</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Allows a render variable of the component to be read or
updated</p></td></tr></tbody></table></div><p>Most of these binding prefixes
allow parameters to be bound to read-only values
; for instance a parameter bound to "message:some-key" will see the message
for "some-key" from its container's message catalog in the field. If the
component tries to update the parameter (by setting the value of the field), a
runtime exception will be thrown to indicate that the value is
read-only.</p><p>Only prop: and var: binding prefixes are updateable (but you
must <em>not</em> use the ${..} syntax here; see the <a shape="rect"
href="#ComponentParameters-dontUseSyntax">warning below</a>).</p><p>Each
parameter has a default prefix, defined by the component, that is used when the
prefix is not provided. The most common are "literal:" and "prop:".</p><p>A
<em>special prefix</em>, "inherit:", is used to support <a shape="rect"
href="#ComponentParameters-InheritedParameterBindings">Inherited Parameter
Bindings</a>.</p><h3 id="ComponentParameters-RenderVariables:Bindings">Render
Variables: Bindings</h3><p>Components can have any number of <em>render
variables</em>. Render variables
are named values with no specific type (they are ultimately stored in a Map).
Render variables are useful for holding simple values, such as loop indices,
that need to be passed from one component to another.</p><p>For example, the
following template code:</p><div class="code panel pdl" style="border-width:
1px;"><div class="codeContent panelContent pdl">
<script class="theme: Default; brush: xml; gutter: false"
type="syntaxhighlighter"><![CDATA[<ul>
<li t:type="loop" source="1..10"
value="index">${index}</li>
</ul>
@@ -361,7 +365,7 @@ public class Title {
return String.format("Maximum field length is %d.", maxLength);
}
]]></script>
-</div></div><p>This form is more like using the "literal:" binding prefix,
except that the literal value is computed by the defaultMessage()
method.</p><p>Obviously, this is a lot more work than simply specifying a
default value as part of the @Parameter annotation. In the few real cases where
this is approach is used, the default binding method will usually deduce a
proper binding, typically in terms of the component's id. For example, the
TextField component will deduce a value parameter that binds to a property of
its container with the same name.</p><p>A default binding method will
<em>only</em> be invoked if the @Parameter annotation does not provide a
default value.</p><h1 id="ComponentParameters-UnboundParameters">Unbound
Parameters</h1><p>If a parameter is not bound (and is optional), then the value
may be read or <em>updated</em> at any time.</p><p>Updates to unbound
parameters cause no side effects. In the first example, the value parameter of
the Count component is not bo
und, and this is perfectly valid.</p><p>Note: updates to such fields are
temporary; when the component <em>finishes rendering</em>, the field will
revert to its default value.</p><p><strong>TODO: This seems contradictory. What
does it mean to update an unbound component parameter when the component is not
rendering?</strong></p><h1
id="ComponentParameters-ParameterTypeCoercion">Parameter Type
Coercion</h1><p>Tapestry includes a mechanism for <a shape="rect"
href="type-coercion.html">coercing types automatically</a>. Most often, this is
used to convert literal strings into appropriate values, but in many cases,
more complex conversions will occur.</p><h1
id="ComponentParameters-ParameterNames">Parameter Names</h1><p>By default,
Tapestry converts from the field name to the parameter name, by stripping off
leading "$" and "_" characters.</p><p>This can be overridden using the name()
attribute of the @Parameter annotation.</p><h1
id="ComponentParameters-DeterminingifBound">Determining i
f Bound</h1><p>In rare cases, you may want to take different behaviors based
on whether a parameter is bound or not. This can be accomplished by querying
the component's resources, which can be <a shape="rect"
href="injection.html">injected</a> into the component using the @<a
shape="rect" class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/annotations/Inject.html">Inject</a>
annotation:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
+</div></div><p>This form is more like using the "literal:" binding prefix,
except that the literal value is computed by the defaultMessage()
method.</p><p>Obviously, this is a lot more work than simply specifying a
default value as part of the @Parameter annotation. In the few real cases where
this is approach is used, the default binding method will usually deduce a
proper binding, typically in terms of the component's id. For example, the
TextField component will deduce a value parameter that binds to a property of
its container with the same name.</p><p>A default binding method will
<em>only</em> be invoked if the @Parameter annotation does not provide a
default value.</p><h1 id="ComponentParameters-UnboundParameters">Unbound
Parameters</h1><p>If a parameter is not bound (and is optional), then the value
may be read or <em>updated</em> at any time.</p><p>Updates to unbound
parameters cause no side effects. In the first example, the value parameter of
the Count component is not bo
und, and this is perfectly valid.</p><p>Note: updates to such fields are
temporary; when the component <em>finishes rendering</em>, the field will
revert to its default value.</p><h1
id="ComponentParameters-ParameterTypeCoercion">Parameter Type
Coercion</h1><p>Main Article: <a shape="rect"
href="parameter-type-coercion.html">Parameter Type Coercion</a></p><p>Tapestry
includes a mechanism for <span class="confluence-link">coercing types
automatically</span>. Most often, this is used to convert literal strings into
appropriate values, but in many cases, more complex conversions will occur.
This mechanism is used for component parameters, such as when an outer
component passes a literal string to an inner component that is expecting an
integer.</p><p>You can easily <a shape="rect"
href="type-coercion.html">contribute new coercions</a> for your own
purposes.</p><h1 id="ComponentParameters-ParameterNames">Parameter
Names</h1><p>By default, Tapestry converts from the field name to the par
ameter name, by stripping off leading "$" and "_" characters.</p><p>This can
be overridden using the name() attribute of the @Parameter annotation.</p><h1
id="ComponentParameters-DeterminingifBound">Determining if Bound</h1><p>In rare
cases, you may want to take different behaviors based on whether a parameter is
bound or not. This can be accomplished by querying the component's resources,
which can be <a shape="rect" href="injection.html">injected</a> into the
component using the @<a shape="rect" class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/annotations/Inject.html">Inject</a>
annotation:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[public class MyComponent
{
@Parameter
Added: websites/production/tapestry/content/parameter-type-coercion.html
==============================================================================
--- websites/production/tapestry/content/parameter-type-coercion.html (added)
+++ websites/production/tapestry/content/parameter-type-coercion.html Mon Dec
15 14:20:11 2014
@@ -0,0 +1,170 @@
+<!DOCTYPE html>
+
+ <!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<html>
+<head>
+ <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
+ <meta http-equiv="x-ua-compatible" content="IE=9">
+ <title>
+ Parameter Type Coercion -- Apache Tapestry
+ </title>
+ <link type="text/css" rel="stylesheet" href="/resources/space.css">
+
+ <link href='/resources/highlighter/styles/shCoreCXF.css' rel='stylesheet'
type='text/css' />
+ <link href='/resources/highlighter/styles/shThemeCXF.css' rel='stylesheet'
type='text/css' />
+ <script src='/resources/highlighter/scripts/shCore.js'
type='text/javascript'></script>
+ <script src='/resources/highlighter/scripts/shBrushJava.js'
type='text/javascript'></script>
+ <script src='/resources/highlighter/scripts/shBrushXml.js'
type='text/javascript'></script>
+ <script src='/resources/highlighter/scripts/shBrushPlain.js'
type='text/javascript'></script>
+ <script type="text/javascript">
+ SyntaxHighlighter.defaults['toolbar'] = false;
+ SyntaxHighlighter.all();
+ </script>
+
+ <link href="/styles/style.css" rel="stylesheet" type="text/css"/>
+
+</head>
+<body>
+ <div class="wrapper bs">
+
+<div id="navigation"><div class="nav">
+<ul class="alternate"><li><a shape="rect"
href="index.html">Home</a></li><li><a shape="rect"
href="getting-started.html">Getting Started</a></li><li><a shape="rect"
href="documentation.html">Documentation</a></li><li><a shape="rect"
href="download.html">Download</a></li><li><a shape="rect"
href="about.html">About</a></li><li><a shape="rect"
href="community.html">Community</a></li><li><a shape="rect"
class="external-link" href="http://www.apache.org/">Apache</a></li><li><a
shape="rect" class="external-link"
href="http://www.apache.org/foundation/sponsorship.html">Sponsorship</a></li><li><a
shape="rect" class="external-link"
href="http://www.apache.org/foundation/thanks.html">Thanks</a></li></ul>
+</div></div>
+
+<div id="top">
+<div id="smallbanner"><div class="searchbox" style="float:right;margin: .3em
1em .1em 1em"><span style="color: #999; font-size: 90%">Tapestry docs, issues,
wikis & blogs:</span>
+<form enctype="application/x-www-form-urlencoded" method="get"
action="http://tapestry.apache.org/search.html">
+ <input type="text" name="q">
+ <input type="submit" value="Search">
+</form>
+
+</div><div class="emblem" style="float:left"><p><a shape="rect"
href="index.html"><img class="confluence-embedded-image
confluence-external-resource"
src="http://tapestry.apache.org/images/tapestry_small.png"
data-image-src="http://tapestry.apache.org/images/tapestry_small.png"></a></p></div><div
class="title" style="float:left; margin: 0 0 0 3em"><h1
id="SmallBanner-PageTitle">Parameter Type Coercion</h1></div></div>
+<div class="clearer"></div>
+</div>
+
+<div class="clearer"></div>
+
+ <div id="breadcrumbs">
+ <a href="index.html">Apache Tapestry</a> > <a
href="documentation.html">Documentation</a> > <a
href="user-guide.html">User Guide</a> > <a
href="parameter-type-coercion.html">Parameter Type Coercion</a>
+ <a class="edit" title="Edit this page (requires approval -- just ask on
the mailing list)"
href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=22872139">edit</a>
+ </div>
+
+<div id="content">
+<div id="ConfluenceContent"><p><strong style="text-align: justify;">Type
Coercion</strong><span style="color: rgb(0,0,0);"> 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.</span></p><p>See <a shape="rect" href="type-coercion.html">Type
Coercer Service</a> for the list of build-in coercions.</p><h2
id="ParameterTypeCoercion-ParameterTypeCoercions">Parameter Type
Coercions</h2><div class="navmenu" style="float:right; background:white;
margin:3px; padding:3px">
+<div class="navmenu" style="float:right; background:#eee; margin:3px;
padding:3px"></div>
+<h3>Related Articles</h3>
+<ul class="content-by-label"><li>
+ <div>
+ <span class="icon icon-page" title="Page">Page:</span>
</div>
+
+ <div class="details">
+ <a shape="rect"
href="supporting-informal-parameters.html">Supporting Informal Parameters</a>
+
+
+ </div>
+ </li><li>
+ <div>
+ <span class="icon icon-page" title="Page">Page:</span>
</div>
+
+ <div class="details">
+ <a shape="rect"
href="enum-parameter-recipe.html">Enum Parameter Recipe</a>
+
+
+ </div>
+ </li><li>
+ <div>
+ <span class="icon icon-page" title="Page">Page:</span>
</div>
+
+ <div class="details">
+ <a shape="rect"
href="default-parameter.html">Default Parameter</a>
+
+
+ </div>
+ </li><li>
+ <div>
+ <span class="icon icon-page" title="Page">Page:</span>
</div>
+
+ <div class="details">
+ <a shape="rect"
href="parameter-type-coercion.html">Parameter Type Coercion</a>
+
+
+ </div>
+ </li><li>
+ <div>
+ <span class="icon icon-page" title="Page">Page:</span>
</div>
+
+ <div class="details">
+ <a shape="rect" href="type-coercion.html">Type
Coercion</a>
+
+
+ </div>
+ </li><li>
+ <div>
+ <span class="icon icon-page" title="Page">Page:</span>
</div>
+
+ <div class="details">
+ <a shape="rect"
href="component-parameters.html">Component Parameters</a>
+
+
+ </div>
+ </li></ul>
+</div><p>Tapestry automatically handles type coercions for <a shape="rect"
href="component-parameters.html">component parameters</a>.</p><p>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.</p><p>For example,
consider the Count component:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[public class Count
+{
+ @Parameter
+ private int start = 1;
+
+ @Parameter(required = true)
+ private int end;
+
+ @Parameter
+ private int value;
+
+ . . .
+]]></script>
+</div></div><p>Here, the type of all three parameters is
<code>int</code>.</p><p>However, it is likely that the component will be used
as so:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
+<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[ Merry Christmas: <t:count
end="3"> Ho! </t:count>
+]]></script>
+</div></div><p>A bare whole number is interpreted by the prop binding prefix
as a <code>long</code>. So this is the <em>long</em> value 3.</p><p>Tapestry
will automatically coerce the bound value, a <code>long</code>, to the
parameter's type, <code>int</code>. This may be a lossy coercion (if the
<code>long</code> represents a number larger than can be stored in an
<code>int</code>).</p><h2
id="ParameterTypeCoercion-TypeCoercerService">TypeCoercer Service</h2><p>Main
Article: <a shape="rect" href="type-coercion.html">Type Coercion</a></p><p>The
TypeCoercer service is responsible for this type coercion. This service is part
of the <a shape="rect" href="ioc.html">tapestry-ioc</a> 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.</p></div>
+</div>
+
+<div class="clearer"></div>
+<div id="footer">
+<div id="footer"><p>Apache Tapestry, Tapestry, Apache, the Apache feather
logo, and the Apache Tapestry project logo are trademarks of The Apache
Software Foundation.<br clear="none">
+</p><p><script type="text/javascript">
+ var _gaq = _gaq || [];
+ _gaq.push(['_setAccount', 'UA-400821-1']);
+ _gaq.push(['_trackPageview']);
+
+ (function() {
+ var ga = document.createElement('script'); ga.type = 'text/javascript';
ga.async = true;
+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' :
'http://www') + '.google-analytics.com/ga.js';
+ var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
+ })();
+</script></p><p></p></div>
+</div>
+ <div id="comments_thread"></div>
+ <script type="text/javascript"
src="https://comments.apache.org/show_comments.lua?site=tapestry&page=http://tapestry.apache.org/parameter-type-coercion.html"
async="true">
+ </script>
+ <noscript>
+ <iframe width="100%" height="500"
src="https://comments.apache.org/iframe.lua?site=tapestry&page=http://tapestry.apache.org/parameter-type-coercion.html"></iframe>
+ </noscript>
+ </div>
+</body>
+</html>
Modified: websites/production/tapestry/content/redirects.html
==============================================================================
--- websites/production/tapestry/content/redirects.html (original)
+++ websites/production/tapestry/content/redirects.html Mon Dec 15 14:20:11 2014
@@ -56,7 +56,7 @@
</div>
<div id="content">
-<div id="ConfluenceContent"><p>These pages only exist to prevent broken links
after a page has been renamed. Each page merely redirects to another
page.</p><p></p><ul class="childpages-macro"><li><a shape="rect"
href="ajax-javascript.html">Ajax & JavaScript</a></li><li><a shape="rect"
href="ajax-components.html">Ajax Components</a></li><li><a shape="rect"
href="first.html">First</a></li><li><a shape="rect"
href="forms.html">Forms</a></li><li><a shape="rect"
href="forms-and-form-components.html">Forms and Form Components</a></li><li><a
shape="rect" href="hilo.html">HiLo</a></li><li><a shape="rect"
href="indexv1.html">IndexV1</a></li><li><a shape="rect"
href="input-validation.html">Input Validation</a></li><li><a shape="rect"
href="ioc-advice.html">IoC - advice</a></li><li><a shape="rect"
href="ioc-autoload.html">IoC - autoload</a></li><li><a shape="rect"
href="ioc-case.html">IoC - case</a></li><li><a shape="rect"
href="ioc-coerce.html">IoC - coerce</a></li><li><a shape="rect" hre
f="ioc-command.html">IoC - command</a></li><li><a shape="rect"
href="ioc-configuration.html">IoC - configuration</a></li><li><a shape="rect"
href="ioc-cookbook-basics.html">IoC cookbook - basics</a></li><li><a
shape="rect" href="ioc-cookbook-override.html">IoC cookbook -
override</a></li><li><a shape="rect" href="ioc-decorator.html">IoC -
decorator</a></li><li><a shape="rect" href="ioc-injection.html">IoC -
injection</a></li><li><a shape="rect" href="ioc-logging.html">IoC -
logging</a></li><li><a shape="rect" href="ioc-module.html">IoC -
module</a></li><li><a shape="rect" href="ioc-order.html">IoC -
order</a></li><li><a shape="rect" href="ioc-overview.html">IoC -
overview</a></li><li><a shape="rect" href="ioc-parallel.html">IoC -
parallel</a></li><li><a shape="rect" href="ioc-pipeline.html">IoC -
pipeline</a></li><li><a shape="rect" href="ioc-provider.html">IoC -
provider</a></li><li><a shape="rect" href="ioc-run.html">IoC -
run</a></li><li><a shape="rect" href="ioc-serialization.ht
ml">IoC - serialization</a></li><li><a shape="rect" href="ioc-shadow.html">IoC
- shadow</a></li><li><a shape="rect" href="ioc-startup.html">IoC -
startup</a></li><li><a shape="rect" href="ioc-strategy.html">IoC -
strategy</a></li><li><a shape="rect" href="ioc-symbols.html">IoC -
symbols</a></li><li><a shape="rect"
href="javascript.html">JavaScript</a></li><li><a shape="rect"
href="loading-the-project-into-eclipse.html">Loading the Project Into
Eclipse</a></li><li><a shape="rect" href="page-and-component-classes.html">Page
And Component Classes</a></li><li><a shape="rect"
href="persistent-state.html">Persistent State</a></li><li><a shape="rect"
href="release-notes-for-532.html">Release Notes for 5.3.2</a></li><li><a
shape="rect" href="reload.html">Reload</a></li><li><a shape="rect"
href="specific-errors.html">Specific Errors</a></li><li><a shape="rect"
href="spring.html">Spring</a></li><li><a shape="rect"
href="statistics.html">Statistics</a></li><li><a shape="rect" href="tapestry-in
version-of-control-container.html">Tapestry Inversion of Control
Container</a></li><li><a shape="rect" href="test.html">Test</a></li><li><a
shape="rect" href="tutorial.html">Tutorial</a></li><li><a shape="rect"
href="upgrade.html">Upgrade</a></li><li><a shape="rect"
href="upload.html">Upload</a></li><li><a shape="rect"
href="userguide.html">Userguide</a></li></ul></div>
+<div id="ConfluenceContent"><p>These pages only exist to prevent broken links
after a page has been renamed. Each page merely redirects to another
page.</p><p></p><ul class="childpages-macro"><li><a shape="rect"
href="ajax-javascript.html">Ajax & JavaScript</a></li><li><a shape="rect"
href="ajax-components.html">Ajax Components</a></li><li><a shape="rect"
href="first.html">First</a></li><li><a shape="rect"
href="forms.html">Forms</a></li><li><a shape="rect"
href="forms-and-form-components.html">Forms and Form Components</a></li><li><a
shape="rect" href="hilo.html">HiLo</a></li><li><a shape="rect"
href="indexv1.html">IndexV1</a></li><li><a shape="rect"
href="input-validation.html">Input Validation</a></li><li><a shape="rect"
href="ioc-advice.html">IoC - advice</a></li><li><a shape="rect"
href="ioc-autoload.html">IoC - autoload</a></li><li><a shape="rect"
href="ioc-case.html">IoC - case</a></li><li><a shape="rect"
href="ioc-coerce.html">IoC - coerce</a></li><li><a shape="rect" hre
f="ioc-command.html">IoC - command</a></li><li><a shape="rect"
href="ioc-configuration.html">IoC - configuration</a></li><li><a shape="rect"
href="ioc-cookbook-basics.html">IoC cookbook - basics</a></li><li><a
shape="rect" href="ioc-cookbook-override.html">IoC cookbook -
override</a></li><li><a shape="rect" href="ioc-decorator.html">IoC -
decorator</a></li><li><a shape="rect" href="ioc-injection.html">IoC -
injection</a></li><li><a shape="rect" href="ioc-logging.html">IoC -
logging</a></li><li><a shape="rect" href="ioc-module.html">IoC -
module</a></li><li><a shape="rect" href="ioc-order.html">IoC -
order</a></li><li><a shape="rect" href="ioc-overview.html">IoC -
overview</a></li><li><a shape="rect" href="ioc-parallel.html">IoC -
parallel</a></li><li><a shape="rect" href="ioc-pipeline.html">IoC -
pipeline</a></li><li><a shape="rect" href="ioc-provider.html">IoC -
provider</a></li><li><a shape="rect" href="ioc-run.html">IoC -
run</a></li><li><a shape="rect" href="ioc-serialization.ht
ml">IoC - serialization</a></li><li><a shape="rect" href="ioc-shadow.html">IoC
- shadow</a></li><li><a shape="rect" href="ioc-startup.html">IoC -
startup</a></li><li><a shape="rect" href="ioc-strategy.html">IoC -
strategy</a></li><li><a shape="rect" href="ioc-symbols.html">IoC -
symbols</a></li><li><a shape="rect"
href="javascript.html">JavaScript</a></li><li><a shape="rect"
href="loading-the-project-into-eclipse.html">Loading the Project Into
Eclipse</a></li><li><a shape="rect" href="page-and-component-classes.html">Page
And Component Classes</a></li><li><a shape="rect"
href="persistent-state.html">Persistent State</a></li><li><a shape="rect"
href="release-notes-for-532.html">Release Notes for 5.3.2</a></li><li><a
shape="rect" href="reload.html">Reload</a></li><li><a shape="rect"
href="specific-errors.html">Specific Errors</a></li><li><a shape="rect"
href="spring.html">Spring</a></li><li><a shape="rect"
href="statistics.html">Statistics</a></li><li><a shape="rect" href="tapestry-in
version-of-control-container.html">Tapestry Inversion of Control
Container</a></li><li><a shape="rect" href="test.html">Test</a></li><li><a
shape="rect" href="tutorial.html">Tutorial</a></li><li><a shape="rect"
href="typecoercer-service.html">TypeCoercer Service</a></li><li><a shape="rect"
href="upgrade.html">Upgrade</a></li><li><a shape="rect"
href="upload.html">Upload</a></li><li><a shape="rect"
href="userguide.html">Userguide</a></li></ul></div>
</div>
<div class="clearer"></div>
Added: websites/production/tapestry/content/type-coercion.data/type-coercer.png
==============================================================================
Binary file - no diff available.
Propchange:
websites/production/tapestry/content/type-coercion.data/type-coercer.png
------------------------------------------------------------------------------
svn:mime-type = image/png
Modified: websites/production/tapestry/content/type-coercion.html
==============================================================================
--- websites/production/tapestry/content/type-coercion.html (original)
+++ websites/production/tapestry/content/type-coercion.html Mon Dec 15 14:20:11
2014
@@ -61,47 +61,28 @@
<div class="clearer"></div>
<div id="breadcrumbs">
- <a href="index.html">Apache Tapestry</a> > <a
href="documentation.html">Documentation</a> > <a
href="user-guide.html">User Guide</a> > <a
href="type-coercion.html">Type Coercion</a>
- <a class="edit" title="Edit this page (requires approval -- just ask on
the mailing list)"
href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=22872139">edit</a>
+ <a href="index.html">Apache Tapestry</a> > <a
href="documentation.html">Documentation</a> > <a
href="user-guide.html">User Guide</a> > <a
href="ioc.html">IoC</a> > <a href="type-coercion.html">Type
Coercion</a>
+ <a class="edit" title="Edit this page (requires approval -- just ask on
the mailing list)"
href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=23338478">edit</a>
</div>
<div id="content">
-<div id="ConfluenceContent"><p><strong style="text-align: justify;">Type
Coercion</strong><span style="color: rgb(0,0,0);"> 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.</span></p><p>See <a shape="rect"
href="typecoercer-service.html">Type Coercer Service</a> for the list of
build-in coercions.</p><h2 id="TypeCoercion-ParameterTypeCoercions">Parameter
Type Coercions</h2><div class="navmenu" style="float:right; background:white;
margin:3px; padding:3px">
-<div class="navmenu" style="float:right; background:#eee; margin:3px;
padding:3px"></div>
+<div id="ConfluenceContent"><style type="text/css">/*<![CDATA[*/
+table.ScrollbarTable {border: none;padding: 3px;width: 100%;padding:
3px;margin: 0px;background-color: #f0f0f0}
+table.ScrollbarTable td.ScrollbarPrevIcon {text-align: center;width:
16px;border: none;}
+table.ScrollbarTable td.ScrollbarPrevName {text-align: left;border: none;}
+table.ScrollbarTable td.ScrollbarParent {text-align: center;border: none;}
+table.ScrollbarTable td.ScrollbarNextName {text-align: right;border: none;}
+table.ScrollbarTable td.ScrollbarNextIcon {text-align: center;width:
16px;border: none;}
+
+/*]]>*/</style><div class="Scrollbar"><table class="ScrollbarTable"><tr><td
colspan="1" rowspan="1" class="ScrollbarPrevIcon"><a shape="rect"
href="service-serialization.html"><img align="middle" border="0"
src="https://cwiki.apache.org/confluence/images/icons/back_16.gif" width="16"
height="16"></a></td><td colspan="1" rowspan="1" class="ScrollbarPrevName"
width="33%"><a shape="rect" href="service-serialization.html">Service
Serialization</a> </td><td colspan="1" rowspan="1" class="ScrollbarParent"
width="33%"><sup><a shape="rect" href="ioc.html"><img align="middle" border="0"
src="https://cwiki.apache.org/confluence/images/icons/up_16.gif" width="8"
height="8"></a></sup><a shape="rect" href="ioc.html">IoC</a></td><td
colspan="1" rowspan="1" class="ScrollbarNextName" width="33%"> <a
shape="rect" href="starting-the-ioc-registry.html">Starting the IoC
Registry</a></td><td colspan="1" rowspan="1" class="ScrollbarNextIcon"><a
shape="rect" href="starting-the-ioc-registry.html"
><img align="middle" border="0"
>src="https://cwiki.apache.org/confluence/images/icons/forwd_16.gif"
>width="16" height="16"></a></td></tr></table></div><div class="navmenu"
>style="float:right; background:white; margin:3px; padding:3px">
+<div class="navmenu" style="float:right; background:#eee; margin:3px;
padding:3px"></div>
<h3>Related Articles</h3>
<ul class="content-by-label"><li>
<div>
<span class="icon icon-page" title="Page">Page:</span>
</div>
<div class="details">
- <a shape="rect"
href="typecoercer-service.html">TypeCoercer Service</a>
-
-
- </div>
- </li><li>
- <div>
- <span class="icon icon-page" title="Page">Page:</span>
</div>
-
- <div class="details">
- <a shape="rect"
href="supporting-informal-parameters.html">Supporting Informal Parameters</a>
-
-
- </div>
- </li><li>
- <div>
- <span class="icon icon-page" title="Page">Page:</span>
</div>
-
- <div class="details">
- <a shape="rect"
href="enum-parameter-recipe.html">Enum Parameter Recipe</a>
-
-
- </div>
- </li><li>
- <div>
- <span class="icon icon-page" title="Page">Page:</span>
</div>
-
- <div class="details">
- <a shape="rect"
href="component-parameters.html">Component Parameters</a>
+ <a shape="rect"
href="parameter-type-coercion.html">Parameter Type Coercion</a>
</div>
@@ -114,34 +95,94 @@
</div>
- </li><li>
- <div>
- <span class="icon icon-page" title="Page">Page:</span>
</div>
-
- <div class="details">
- <a shape="rect"
href="default-parameter.html">Default Parameter</a>
-
-
- </div>
</li></ul>
-</div><p>Tapestry automatically handles type coercions for <a shape="rect"
href="component-parameters.html">component parameters</a>.</p><p>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.</p><p>For example,
consider the Count component:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[public class Count
-{
- @Parameter
- private int start = 1;
-
- @Parameter(required = true)
- private int end;
-
- @Parameter
- private int value;
-
- . . .
+</div><p><strong>Type Coercion</strong> 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.</p><p>Although type
coercions happen more inside tapestry-core (including <a shape="rect"
href="parameter-type-coercion.html">coercions of <span
class="confluence-link">component parameters</span></a><span
class="confluence-link"> </span>), they may also happen inside
tapestry-ioc, such as when injecting a value, rather than a service, into a
builder method.</p><p>Like everything else in Tapestry, type coercions are
extensible. At the root is the <a shape="rect" class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/services/TypeCoercer.html">TypeCoercer</a>
service. Its configuration consists of a number of <a shape="rect"
class="external-link" href="http://tapest
ry.apache.org/current/apidocs/org/apache/tapestry5/ioc/services/CoercionTuple.html">CoercionTuples</a>.
Each tuple defines how to coerce from one type to another. The initial set of
coercions is focused primarily on coercions between different numeric
types:</p><p><img class="confluence-embedded-image"
src="type-coercion.data/type-coercer.png"
data-image-src="/confluence/download/attachments/23338478/type-coercer.png?version=1&modificationDate=1290973716000&api=v2"></p><h2
id="TypeCoercion-DefaultTypeCoercions">Default Type Coercions</h2><p>There are
a few special coercions related to <code>null</code> there; <code>Object</code>
--> <code>List</code> wraps a lone object as a singleton list, we then need
<code>null</code> --> <code>List</code> to ensure that <code>null</code>
stays <code>null</code> (rather than a singleton list whose lone element is a
<code>null</code>).</p><p>Tapestry can <em>interpolate</em> necessary
coercions. For example, say it is necessary to co
erce a <code>StringBuffer</code> to an <code>Integer</code>; the TypeCoercer
service will chain together a series of
coercions:</p><ul><li><code>Object</code> -->
<code>String</code></li><li><code>String</code> -->
<code>Long</code></li><li><code>Long</code> -->
<code>Integer</code></li></ul><h2 id="TypeCoercion-Coercingfromnull">Coercing
from null</h2><p>Coercing from <code>null</code> is special; it is not a
spanning search as with the other types. Either there is a specific coercion
from <code>null</code> to the desired type, or no coercion takes places (and
the coerced value is <code>null</code>).</p><p>The only built-in
<code>null</code> coercion is from <code>null</code> to <code>boolean</code>
(which is always false).</p><h2 id="TypeCoercion-ListofCoercions">List of
Coercions</h2><p>As of Tapestry versions 5.1 and 5.2, the following coercions
are available:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
+<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[Double --> Float
+Float --> Double
+Long --> Boolean
+Long --> Byte
+Long --> Double
+Long --> Integer
+Long --> Short
+Number --> Long
+Object --> Object[]
+Object --> String
+Object --> java.util.List
+Object[] --> java.util.List
+String --> Boolean
+String --> Double
+String --> Long
+String --> java.io.File
+String --> java.math.BigDecimal
+String --> java.math.BigInteger
+String --> java.text.DateFormat
+String --> java.util.regex.Pattern
+String --> org.apache.tapestry5.Renderable
+String --> org.apache.tapestry5.SelectModel
+String --> org.apache.tapestry5.corelib.ClientValidation
+String --> org.apache.tapestry5.corelib.LoopFormState
+String --> org.apache.tapestry5.corelib.SubmitMode
+String --> org.apache.tapestry5.corelib.data.BlankOption
+String --> org.apache.tapestry5.corelib.data.GridPagerPosition
+String --> org.apache.tapestry5.corelib.data.InsertPosition
+String --> org.apache.tapestry5.ioc.Resource
+String --> org.apache.tapestry5.ioc.util.TimeInterval
+boolean[] --> java.util.List
+byte[] --> java.util.List
+char[] --> java.util.List
+double[] --> java.util.List
+float[] --> java.util.List
+int[] --> java.util.List
+java.math.BigDecimal --> Double
+java.util.Collection --> Boolean
+java.util.Collection --> Object[]
+java.util.Collection --> org.apache.tapestry5.grid.GridDataSource
+java.util.Date --> java.util.Calendar
+java.util.List --> org.apache.tapestry5.SelectModel
+java.util.Map --> org.apache.tapestry5.SelectModel
+long[] --> java.util.List
+null --> Boolean
+null --> org.apache.tapestry5.grid.GridDataSource
+org.apache.tapestry5.ComponentResources -->
org.apache.tapestry5.PropertyOverrides
+org.apache.tapestry5.PrimaryKeyEncoder --> org.apache.tapestry5.ValueEncoder
+org.apache.tapestry5.Renderable --> org.apache.tapestry5.Block
+org.apache.tapestry5.Renderable -->
org.apache.tapestry5.runtime.RenderCommand
+org.apache.tapestry5.ioc.util.TimeInterval --> Long
+org.apache.tapestry5.runtime.ComponentResourcesAware -->
org.apache.tapestry5.ComponentResources
+short[] --> java.util.List
]]></script>
-</div></div><p>Here, the type of all three parameters is
<code>int</code>.</p><p>However, it is likely that the component will be used
as so:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[ Merry Christmas: <t:count
end="3"> Ho! </t:count>
+</div></div><h2 id="TypeCoercion-ContributingNewCoercions">Contributing New
Coercions</h2><p>TypeCoercer is extensible; you may add new coercions as
desired. For example, let's say you have a <code>Money</code> type that
represents an amount of some currency, and you want to be able to convert from
<code>BigDecimal</code> to <code>Money</code>. Further, let's assume that
<code>Money</code> has a constructor that accepts a <code>BigDecimal</code> as
its parameter. We'll use a little Tapestry IOC configuration jujitsu to inform
the TypeCoercer about this coercion.</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeHeader panelHeader pdl"
style="border-bottom-width: 1px;"><b>AppModule.java (partial)</b></div><div
class="codeContent panelContent pdl">
+<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[public static void
contributeTypeCoercer(Configuration<CoercionTuple> configuration)
+{
+ Coercion<BigDecimal, Money> coercion = new Coercion<BigDecimal,
Money>()
+ {
+ public Money coerce(BigDecimal input)
+ {
+ return new Money(input);
+ }
+ };
+
+ configuration.add(new CoercionTuple<BigDecimal,
Money>(BigDecimal.class, Money.class, coercion));
+}]]></script>
+</div></div><p>Further, since TypeCoercer knows how to convert
<code>Double</code> to <code>BigDecimal</code>, or even <code>Integer</code>
(to <code>Long</code> to <code>Double</code>) to <code>BigDecimal</code>, all
of those coercions would work as well.</p><p>When creating a coercion from
<code>null</code>, use <code>Void.class</code> as the source type. For example,
the built-in coercion from <code>null</code> to <code>Boolean</code> is
implemented as:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeHeader panelHeader pdl" style="border-bottom-width:
1px;"><b>AppModule.java (partial)</b></div><div class="codeContent panelContent
pdl">
+<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[ configuration.add(new
CoercionTuple(void.class, Boolean.class,
+ new Coercion<Void, Boolean>()
+ {
+ public Boolean coerce(Void input)
+ {
+ return false;
+ }
+ }));
]]></script>
-</div></div><p>A bare whole number is interpreted by the prop binding prefix
as a <code>long</code>. So this is the <em>long</em> value 3.</p><p>Tapestry
will automatically coerce the bound value, a <code>long</code>, to the
parameter's type, <code>int</code>. This may be a lossy coercion (if the
<code>long</code> represents a number larger than can be stored in an
<code>int</code>).</p><h2 id="TypeCoercion-TypeCoercerService">TypeCoercer
Service</h2><p>Main Article: <a shape="rect"
href="typecoercer-service.html">TypeCoercer Service</a></p><p>The TypeCoercer
service is responsible for this type coercion. This service is part of the <a
shape="rect" href="ioc.html">tapestry-ioc</a> 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.</p></div>
+</div></div><style type="text/css">/*<![CDATA[*/
+table.ScrollbarTable {border: none;padding: 3px;width: 100%;padding:
3px;margin: 0px;background-color: #f0f0f0}
+table.ScrollbarTable td.ScrollbarPrevIcon {text-align: center;width:
16px;border: none;}
+table.ScrollbarTable td.ScrollbarPrevName {text-align: left;border: none;}
+table.ScrollbarTable td.ScrollbarParent {text-align: center;border: none;}
+table.ScrollbarTable td.ScrollbarNextName {text-align: right;border: none;}
+table.ScrollbarTable td.ScrollbarNextIcon {text-align: center;width:
16px;border: none;}
+
+/*]]>*/</style><div class="Scrollbar"><table class="ScrollbarTable"><tr><td
colspan="1" rowspan="1" class="ScrollbarPrevIcon"><a shape="rect"
href="service-serialization.html"><img align="middle" border="0"
src="https://cwiki.apache.org/confluence/images/icons/back_16.gif" width="16"
height="16"></a></td><td colspan="1" rowspan="1" class="ScrollbarPrevName"
width="33%"><a shape="rect" href="service-serialization.html">Service
Serialization</a> </td><td colspan="1" rowspan="1" class="ScrollbarParent"
width="33%"><sup><a shape="rect" href="ioc.html"><img align="middle" border="0"
src="https://cwiki.apache.org/confluence/images/icons/up_16.gif" width="8"
height="8"></a></sup><a shape="rect" href="ioc.html">IoC</a></td><td
colspan="1" rowspan="1" class="ScrollbarNextName" width="33%"> <a
shape="rect" href="starting-the-ioc-registry.html">Starting the IoC
Registry</a></td><td colspan="1" rowspan="1" class="ScrollbarNextIcon"><a
shape="rect" href="starting-the-ioc-registry.html"
><img align="middle" border="0"
>src="https://cwiki.apache.org/confluence/images/icons/forwd_16.gif"
>width="16" height="16"></a></td></tr></table></div></div>
</div>
<div class="clearer"></div>
Modified: websites/production/tapestry/content/typecoercer-service.html
==============================================================================
--- websites/production/tapestry/content/typecoercer-service.html (original)
+++ websites/production/tapestry/content/typecoercer-service.html Mon Dec 15
14:20:11 2014
@@ -26,16 +26,6 @@
</title>
<link type="text/css" rel="stylesheet" href="/resources/space.css">
- <link href='/resources/highlighter/styles/shCoreCXF.css' rel='stylesheet'
type='text/css' />
- <link href='/resources/highlighter/styles/shThemeCXF.css' rel='stylesheet'
type='text/css' />
- <script src='/resources/highlighter/scripts/shCore.js'
type='text/javascript'></script>
- <script src='/resources/highlighter/scripts/shBrushJava.js'
type='text/javascript'></script>
- <script src='/resources/highlighter/scripts/shBrushXml.js'
type='text/javascript'></script>
- <script src='/resources/highlighter/scripts/shBrushPlain.js'
type='text/javascript'></script>
- <script type="text/javascript">
- SyntaxHighlighter.defaults['toolbar'] = false;
- SyntaxHighlighter.all();
- </script>
<link href="/styles/style.css" rel="stylesheet" type="text/css"/>
@@ -61,179 +51,12 @@
<div class="clearer"></div>
<div id="breadcrumbs">
- <a href="index.html">Apache Tapestry</a> > <a
href="documentation.html">Documentation</a> > <a
href="user-guide.html">User Guide</a> > <a
href="ioc.html">IoC</a> > <a
href="typecoercer-service.html">TypeCoercer Service</a>
- <a class="edit" title="Edit this page (requires approval -- just ask on
the mailing list)"
href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=23338478">edit</a>
+ <a href="index.html">Apache Tapestry</a> > <a
href="index.html">Index</a> > <a
href="redirects.html">Redirects</a> > <a
href="typecoercer-service.html">TypeCoercer Service</a>
+ <a class="edit" title="Edit this page (requires approval -- just ask on
the mailing list)"
href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=50234427">edit</a>
</div>
<div id="content">
-<div id="ConfluenceContent"><style type="text/css">/*<![CDATA[*/
-table.ScrollbarTable {border: none;padding: 3px;width: 100%;padding:
3px;margin: 0px;background-color: #f0f0f0}
-table.ScrollbarTable td.ScrollbarPrevIcon {text-align: center;width:
16px;border: none;}
-table.ScrollbarTable td.ScrollbarPrevName {text-align: left;border: none;}
-table.ScrollbarTable td.ScrollbarParent {text-align: center;border: none;}
-table.ScrollbarTable td.ScrollbarNextName {text-align: right;border: none;}
-table.ScrollbarTable td.ScrollbarNextIcon {text-align: center;width:
16px;border: none;}
-
-/*]]>*/</style><div class="Scrollbar"><table class="ScrollbarTable"><tr><td
colspan="1" rowspan="1" class="ScrollbarPrevIcon"><a shape="rect"
href="service-serialization.html"><img align="middle" border="0"
src="https://cwiki.apache.org/confluence/images/icons/back_16.gif" width="16"
height="16"></a></td><td colspan="1" rowspan="1" class="ScrollbarPrevName"
width="33%"><a shape="rect" href="service-serialization.html">Service
Serialization</a> </td><td colspan="1" rowspan="1" class="ScrollbarParent"
width="33%"><sup><a shape="rect" href="ioc.html"><img align="middle" border="0"
src="https://cwiki.apache.org/confluence/images/icons/up_16.gif" width="8"
height="8"></a></sup><a shape="rect" href="ioc.html">IoC</a></td><td
colspan="1" rowspan="1" class="ScrollbarNextName" width="33%"> <a
shape="rect" href="starting-the-ioc-registry.html">Starting the IoC
Registry</a></td><td colspan="1" rowspan="1" class="ScrollbarNextIcon"><a
shape="rect" href="starting-the-ioc-registry.html"
><img align="middle" border="0"
>src="https://cwiki.apache.org/confluence/images/icons/forwd_16.gif"
>width="16" height="16"></a></td></tr></table></div>
-
-<h1 id="TypeCoercerService-TypeCoercion">Type Coercion</h1>
-
-<div class="navmenu" style="float:right; background:white; margin:3px;
padding:3px">
-<div class="navmenu" style="float:right; background:#eee; margin:3px;
padding:3px"></div>
-<h3>Related Articles</h3>
-<ul class="content-by-label"><li>
- <div>
- <span class="icon icon-page" title="Page">Page:</span>
</div>
-
- <div class="details">
- <a shape="rect"
href="typecoercer-service.html">TypeCoercer Service</a>
-
-
- </div>
- </li><li>
- <div>
- <span class="icon icon-page" title="Page">Page:</span>
</div>
-
- <div class="details">
- <a shape="rect" href="type-coercion.html">Type
Coercion</a>
-
-
- </div>
- </li></ul>
-</div>
-
-<p><strong>Type Coercion</strong> 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.</p>
-
-<p>Although type coercions happen more inside tapestry-core (including
coercions of <a shape="rect" href="component-parameters.html">component
parameters</a>), they may also happen inside tapestry-ioc, such as when
injecting a value, rather than a service, into a builder method.</p>
-
-<p>Like everything else in Tapestry, type coercions are extensible. At the
root is the <a shape="rect" class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/services/TypeCoercer.html">TypeCoercer</a>
service. Its configuration consists of a number of <a shape="rect"
class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/services/CoercionTuple.html">CoercionTuples</a>.
Each tuple defines how to coerce from one type to another. The initial set of
coercions is focused primarily on coercions between different numeric types:</p>
-
-<p><img class="confluence-embedded-image"
src="typecoercer-service.data/type-coercer.png"
data-image-src="/confluence/download/attachments/23338478/type-coercer.png?version=1&modificationDate=1290973716000&api=v2"></p>
-
-<h2 id="TypeCoercerService-DefaultTypeCoercions">Default Type Coercions</h2>
-
-<p>There are a few special coercions related to <code>null</code> there;
<code>Object</code> --> <code>List</code> wraps a lone object as a singleton
list, we then need <code>null</code> --> <code>List</code> to ensure that
<code>null</code> stays <code>null</code> (rather than a singleton list whose
lone element is a <code>null</code>).</p>
-
-<p>Tapestry can <em>interpolate</em> necessary coercions. For example, say it
is necessary to coerce a <code>StringBuffer</code> to an <code>Integer</code>;
the TypeCoercer service will chain together a series of coercions:</p>
-
-<ul><li><code>Object</code> -->
<code>String</code></li><li><code>String</code> -->
<code>Long</code></li><li><code>Long</code> -->
<code>Integer</code></li></ul>
-
-
-<h2 id="TypeCoercerService-Coercingfromnull">Coercing from null</h2>
-
-<p>Coercing from <code>null</code> is special; it is not a spanning search as
with the other types. Either there is a specific coercion from
<code>null</code> to the desired type, or no coercion takes places (and the
coerced value is <code>null</code>).</p>
-
-<p>The only built-in <code>null</code> coercion is from <code>null</code> to
<code>boolean</code> (which is always false).</p>
-
-<h2 id="TypeCoercerService-ListofCoercions">List of Coercions</h2>
-
-<p>As of Tapestry versions 5.1 and 5.2, the following coercions are
available:</p>
-
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[
-Double --> Float
-Float --> Double
-Long --> Boolean
-Long --> Byte
-Long --> Double
-Long --> Integer
-Long --> Short
-Number --> Long
-Object --> Object[]
-Object --> String
-Object --> java.util.List
-Object[] --> java.util.List
-String --> Boolean
-String --> Double
-String --> Long
-String --> java.io.File
-String --> java.math.BigDecimal
-String --> java.math.BigInteger
-String --> java.text.DateFormat
-String --> java.util.regex.Pattern
-String --> org.apache.tapestry5.Renderable
-String --> org.apache.tapestry5.SelectModel
-String --> org.apache.tapestry5.corelib.ClientValidation
-String --> org.apache.tapestry5.corelib.LoopFormState
-String --> org.apache.tapestry5.corelib.SubmitMode
-String --> org.apache.tapestry5.corelib.data.BlankOption
-String --> org.apache.tapestry5.corelib.data.GridPagerPosition
-String --> org.apache.tapestry5.corelib.data.InsertPosition
-String --> org.apache.tapestry5.ioc.Resource
-String --> org.apache.tapestry5.ioc.util.TimeInterval
-boolean[] --> java.util.List
-byte[] --> java.util.List
-char[] --> java.util.List
-double[] --> java.util.List
-float[] --> java.util.List
-int[] --> java.util.List
-java.math.BigDecimal --> Double
-java.util.Collection --> Boolean
-java.util.Collection --> Object[]
-java.util.Collection --> org.apache.tapestry5.grid.GridDataSource
-java.util.Date --> java.util.Calendar
-java.util.List --> org.apache.tapestry5.SelectModel
-java.util.Map --> org.apache.tapestry5.SelectModel
-long[] --> java.util.List
-null --> Boolean
-null --> org.apache.tapestry5.grid.GridDataSource
-org.apache.tapestry5.ComponentResources -->
org.apache.tapestry5.PropertyOverrides
-org.apache.tapestry5.PrimaryKeyEncoder --> org.apache.tapestry5.ValueEncoder
-org.apache.tapestry5.Renderable --> org.apache.tapestry5.Block
-org.apache.tapestry5.Renderable -->
org.apache.tapestry5.runtime.RenderCommand
-org.apache.tapestry5.ioc.util.TimeInterval --> Long
-org.apache.tapestry5.runtime.ComponentResourcesAware -->
org.apache.tapestry5.ComponentResources
-short[] --> java.util.List
-]]></script>
-</div></div>
-
-
-<h2 id="TypeCoercerService-ContributingNewCoercions">Contributing New
Coercions</h2>
-
-<p>TypeCoercer is extensible; you may add new coercions as desired. For
example, let's say you have a <code>Money</code> type that represents an amount
of some currency, and you want to be able to convert from
<code>BigDecimal</code> to <code>Money</code>. Further, let's assume that
<code>Money</code> has a constructor that accepts a <code>BigDecimal</code> as
its parameter. We'll use a little Tapestry IOC configuration jujitsu to inform
the TypeCoercer about this coercion.</p>
-
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[
-public static void contributeTypeCoercer(Configuration<CoercionTuple>
configuration)
-{
- Coercion<BigDecimal, Money> coercion = new Coercion<BigDecimal,
Money>()
- {
- public Money coerce(BigDecimal input)
- {
- return new Money(input);
- }
- };
-
- configuration.add(new CoercionTuple<BigDecimal,
Money>(BigDecimal.class, Money.class, coercion));
-}]]></script>
-</div></div>
-
-<p>Further, since TypeCoercer knows how to convert <code>Double</code> to
<code>BigDecimal</code>, or even <code>Integer</code> (to <code>Long</code> to
<code>Double</code>) to <code>BigDecimal</code>, all of those coercions would
work as well.</p>
-
-<p>When creating a coercion from <code>null</code>, use
<code>Void.class</code> as the source type. For example, the built-in coercion
from <code>null</code> to <code>Boolean</code> is implemented as:</p>
-
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="theme: Default; brush: java; gutter: false"
type="syntaxhighlighter"><![CDATA[
- configuration.add(new CoercionTuple(void.class, Boolean.class,
- new Coercion<Void, Boolean>()
- {
- public Boolean coerce(Void input)
- {
- return false;
- }
- }));
-]]></script>
-</div></div>
-
-<style type="text/css">/*<![CDATA[*/
-table.ScrollbarTable {border: none;padding: 3px;width: 100%;padding:
3px;margin: 0px;background-color: #f0f0f0}
-table.ScrollbarTable td.ScrollbarPrevIcon {text-align: center;width:
16px;border: none;}
-table.ScrollbarTable td.ScrollbarPrevName {text-align: left;border: none;}
-table.ScrollbarTable td.ScrollbarParent {text-align: center;border: none;}
-table.ScrollbarTable td.ScrollbarNextName {text-align: right;border: none;}
-table.ScrollbarTable td.ScrollbarNextIcon {text-align: center;width:
16px;border: none;}
-
-/*]]>*/</style><div class="Scrollbar"><table class="ScrollbarTable"><tr><td
colspan="1" rowspan="1" class="ScrollbarPrevIcon"><a shape="rect"
href="service-serialization.html"><img align="middle" border="0"
src="https://cwiki.apache.org/confluence/images/icons/back_16.gif" width="16"
height="16"></a></td><td colspan="1" rowspan="1" class="ScrollbarPrevName"
width="33%"><a shape="rect" href="service-serialization.html">Service
Serialization</a> </td><td colspan="1" rowspan="1" class="ScrollbarParent"
width="33%"><sup><a shape="rect" href="ioc.html"><img align="middle" border="0"
src="https://cwiki.apache.org/confluence/images/icons/up_16.gif" width="8"
height="8"></a></sup><a shape="rect" href="ioc.html">IoC</a></td><td
colspan="1" rowspan="1" class="ScrollbarNextName" width="33%"> <a
shape="rect" href="starting-the-ioc-registry.html">Starting the IoC
Registry</a></td><td colspan="1" rowspan="1" class="ScrollbarNextIcon"><a
shape="rect" href="starting-the-ioc-registry.html"
><img align="middle" border="0"
>src="https://cwiki.apache.org/confluence/images/icons/forwd_16.gif"
>width="16" height="16"></a></td></tr></table></div></div>
+<div id="ConfluenceContent"><p>This page has moved to <a shape="rect"
href="type-coercion.html">Type Coercion</a></p></div>
</div>
<div class="clearer"></div>