You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by bu...@apache.org on 2013/02/25 04:22:11 UTC

svn commit: r851830 - in /websites/production/tapestry/content: cache/main.pageCache injection.html

Author: buildbot
Date: Mon Feb 25 03:22:11 2013
New Revision: 851830

Log:
Production update by buildbot for tapestry

Modified:
    websites/production/tapestry/content/cache/main.pageCache
    websites/production/tapestry/content/injection.html

Modified: websites/production/tapestry/content/cache/main.pageCache
==============================================================================
Binary files - no diff available.

Modified: websites/production/tapestry/content/injection.html
==============================================================================
--- websites/production/tapestry/content/injection.html (original)
+++ websites/production/tapestry/content/injection.html Mon Feb 25 03:22:11 2013
@@ -56,11 +56,15 @@
   </div>
 
 <div id="content">
-<div id="ConfluenceContent"><h1><a shape="rect" name="Injection-InjectionwithComponents"></a>Injection with Components</h1>
+<div id="ConfluenceContent"><h1><a shape="rect" name="Injection-Injection"></a>Injection</h1>
+
+<p><b>Injection</b> is Tapestry's way of making a dependency &#8211; such as a resource, asset, component, block or service &#8211; available in a page, component, mixin or service class.</p>
+
+<p>Injection is a key concept in Tapestry, and it is used in several different but related ways.</p>
 
 <div class="navmenu" style="float:right; background:#eee; margin:3px; padding:3px"><table class="tableview" width="100%"><tr><th colspan="1" rowspan="1" style="padding: 3px 3px 3px 0px">Related Articles</th></tr><tr><td colspan="1" rowspan="1">
                                  <span class="icon icon-page" title="Page">Page:</span>
-                         <a shape="rect" href="injection-in-detail.html">Injection in Detail</a>
+                         <a shape="rect" href="injection-faq.html">Injection FAQ</a>
         
                                             </td></tr><tr><td colspan="1" rowspan="1">
                                  <span class="icon icon-page" title="Page">Page:</span>
@@ -68,46 +72,50 @@
         
                                             </td></tr><tr><td colspan="1" rowspan="1">
                                  <span class="icon icon-page" title="Page">Page:</span>
-                         <a shape="rect" href="injection-faq.html">Injection FAQ</a>
+                         <a shape="rect" href="injection-in-detail.html">Injection in Detail</a>
         
                                             </td></tr></table>
 </div>
 
-<p>A key concept in Tapestry is the use of <b>injection</b>. The term <em>Injection</em> in Tapestry is used in several related ways. The Tapestry IoC container makes use of one form of injection, via parameters to service builder methods (see <a shape="rect" href="injection-in-detail.html" title="Injection in Detail">Injection in Detail</a>).</p>
+<h2><a shape="rect" name="Injection-InjectioninTapestryIOCServices"></a>Injection in Tapestry IOC Services</h2>
+
+<p>Main Article: <a shape="rect" href="tapestry-ioc-overview.html" title="Tapestry IoC Overview">Tapestry IoC Overview</a></p>
 
-<p>For components, however, Tapestry takes a completely different tack: injection directly into instance variables.</p>
+<p>The Tapestry IoC container makes use of injection primarily through constructors and via parameters to service builder methods.</p>
 
-<h2><a shape="rect" name="Injection-@InjectAnnotation"></a>@Inject Annotation</h2>
+<h2><a shape="rect" name="Injection-InjectioninComponentClasses"></a>Injection in Component Classes</h2>
 
-<p>The @<a shape="rect" class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/annotations/Inject.html">Inject annotation</a> is used to identify fields that will contain injected services and other resources.</p>
+<p>For components, however, Tapestry takes a completely different tack: injection directly into component fields.</p>
+
+<p>The @<a shape="rect" class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/annotations/Inject.html">Inject</a> annotation is used to identify fields that will contain injected services and other resources.</p>
 
 <p>Tapestry allows for two kinds of injection:</p>
 
-<ul><li><b>Explicit injection</b>, where the particular service to be injected is specified.</li><li><b>Default injection</b>, where Tapestry determines the object to inject into the field based on its type.</li></ul>
+<ul><li><b>Default injection</b>, where Tapestry determines the object to inject into the field based on its type.</li><li><b>Explicit injection</b>, where the particular service to be injected is specified.</li></ul>
 
 
 <p>In both cases, the field is transformed into a read only value. As elsewhere in Tapestry, this transformation occurs at runtime (which is very important in terms of being able to test your components). Attempting to update an injected field will result in a runtime exception.</p>
 
 <p>In addition, there are a few special cases that are triggered by specific field types, or additional annotations, in addition, to @Inject, on a field.</p>
 
-<h3><a shape="rect" name="Injection-AssetInjection"></a>Asset Injection</h3>
-
-<p>When the @<a shape="rect" class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/annotations/Path.html">Path</a> annotation is also present, then the injected value (relative to the component) will be a localized <a shape="rect" href="assets.html" title="Assets">asset</a>.</p>
+<h3><a shape="rect" name="Injection-BlockInjection"></a>Block Injection</h3>
 
-<p>Symbols in the annotation value are expanded.</p>
+<p>For field type <a shape="rect" class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/Block.html">Block</a>, the value of the Inject annotation is the id of the <a shape="rect" href="component-templates.html#ComponentTemplates-block">&lt;t:block&gt;</a> element within the component's template. Normally, the id of the block is determined from the field name (after stripping out any leading "_" and "$" characters):</p>
 
-<h3><a shape="rect" name="Injection-BlockInjection"></a>Block Injection</h3>
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<pre class="code-java">
+@Inject
+<span class="code-keyword">private</span> Block foo;
+</pre>
+</div></div>
 
-<p>For field type <a shape="rect" class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/Block.html">Block</a>, the value of the Inject annotation is the id of the <a shape="rect" href="component-templates.html#ComponentTemplates-block">&lt;block&gt; element</a> within the component's template. Normally, the id of the block is determined from the field name (after stripping out leading "_" and "$" characters). Where that is not appropriate, an @<a shape="rect" class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/annotations/Id.html">Id</a> annotation can be supplied:</p>
+<p>Where that is not appropriate, an @<a shape="rect" class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/annotations/Id.html">Id</a> annotation can be supplied:</p>
 
 <div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
 <pre class="code-java">
-  @Inject
-  <span class="code-keyword">private</span> Block foo;
-  
-  @Inject
-  @Id(<span class="code-quote">"bar"</span>)
-  <span class="code-keyword">private</span> Block barBlock;
+@Inject
+@Id(<span class="code-quote">"bar"</span>)
+<span class="code-keyword">private</span> Block barBlock;
 </pre>
 </div></div>
 
@@ -145,11 +153,51 @@
 <ul><li><b>org.apache.tapestry5.ioc.Messages</b> &#8211; The component message catalog for the component, from which <a shape="rect" href="#Injection-localization.html">localized</a> messages can be generated.</li></ul>
 
 
-<h2><a shape="rect" name="Injection-ExplicitServiceInjection"></a>Explicit Service Injection</h2>
+<h3><a shape="rect" name="Injection-AssetInjection"></a>Asset Injection</h3>
 
-<p>Here, a specific object is requested. A @<a shape="rect" class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/annotations/Service.html">Service</a> annotation is used to identify the service name.</p>
+<p>Main Article: <a shape="rect" href="assets.html" title="Assets">Assets</a></p>
+
+<p>When the @<a shape="rect" class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/annotations/Path.html">Path</a> annotation is also present, then the injected value (relative to the component) will be a localized asset.</p>
 
-<p>Example:</p>
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<pre class="code-java">
+@Inject
+@Path(<span class="code-quote">"context:images/top_banner.png"</span>)
+<span class="code-keyword">private</span> Asset banner;
+</pre>
+</div></div>
+
+<p>Symbols in the annotation value are expanded.</p>
+
+<h3><a shape="rect" name="Injection-ServiceInjection"></a>Service Injection</h3>
+
+<p>Here, a custom EmployeeService service is injected, but any custom or built-in service may be injected in the same way. </p>
+
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<pre class="code-java">
+@Inject
+<span class="code-keyword">private</span> EmployeeService employeeService;
+</pre>
+</div></div>
+
+<p>A large number of services are provided by Tapestry. See the following packages:</p>
+
+<div class="navmenu" style="float:left; background:white; margin:3px; padding:3px"><ul><li><a shape="rect" class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/services/package-summary.html">Core Services</a></li><li><a shape="rect" class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/services/ajax/package-summary.html">AJAX Services</a></li><li><a shape="rect" class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/services/assets/package-summary.html">Assets Services</a></li><li><a shape="rect" class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/services/dynamic/package-summary.html">Dynamic Component Services</a></li></ul>
+</div>
+
+<div class="navmenu" style="float:left; background:white; margin:3px; padding:3px"><ul><li><a shape="rect" class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/services/javascript/package-summary.html">JavaScript Services</a></li><li><a shape="rect" class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/services/linktransform/package-summary.html">Link Transformation Services</a></li><li><a shape="rect" class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/services/messages/package-summary.html">Message Services</a></li><li><a shape="rect" class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/services/meta/package-summary.html">Component Metadata Services</a></li></ul>
+</div>
+
+<div class="navmenu" style="float:left; background:white; margin:3px; padding:3px"><ul><li><a shape="rect" class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/services/pageload/package-summary.html">Page Loading Services</a></li><li><a shape="rect" class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/services/security/package-summary.html">Security Services</a></li><li><a shape="rect" class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/services/templates/package-summary.html">Template Services</a></li><li><a shape="rect" class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/services/transform/package-summary.html">Class Transformation Services</a></li></ul>
+</div>
+
+<div class="navmenu" style="float:left; background:white; margin:3px; padding:3px"><ul><li><a shape="rect" class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/services/package-summary.html">Tapestry IOC Services</a></li><li><a shape="rect" class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/services/cron/package-summary.html">Tapestry IOC Cron Services</a></li><li><a shape="rect" class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/kaptcha/services/package-summary.html">Kaptcha Services</a></li><li><a shape="rect" class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/upload/services/package-summary.html">File Upload Services</a></li></ul>
+</div>
+<div style="clear:both"></div>
+
+<h3><a shape="rect" name="Injection-ExplicitServiceInjection"></a>Explicit Service Injection</h3>
+
+<p>Here, a specific object is requested. A @<a shape="rect" class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/annotations/Service.html">Service</a> annotation is used to identify the service name.</p>
 
 <div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
 <pre class="code-java">
@@ -159,7 +207,7 @@
 </pre>
 </div></div>
 
-<p>This is generally not necessary; you should always be able to identify the service to be injected just by type, not by explicit id. Explicit ids have the disadvantage of not being refactoring-safe: this won't happen with the Request service, but perhaps in your own ... if you rename the service interface and rename the service id to match, your existing injections using the explicit service id will break.</p>
+<p>This is generally not necessary; you should always be able to identify the service to be injected just by type, not by explicit id. Explicit ids have the disadvantage of not being refactoring-safe: this won't happen with the Request service, but perhaps in your own code ... if you rename the service interface and rename the service id to match, your existing injections using the explicit service id will break.</p>
 
 <h2><a shape="rect" name="Injection-DefaultInjection"></a>Default Injection</h2>