Modified:
websites/production/tapestry/content/integration-with-existing-applications.html
==============================================================================
---
websites/production/tapestry/content/integration-with-existing-applications.html
(original)
+++
websites/production/tapestry/content/integration-with-existing-applications.html
Sat Feb 3 18:21:36 2018
@@ -27,6 +27,16 @@
</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>
+ SyntaxHighlighter.defaults['toolbar'] = false;
+ SyntaxHighlighter.all();
+ </script>
<link href="/styles/style.css" rel="stylesheet" type="text/css"/>
@@ -67,7 +77,8 @@
</div>
<div id="content">
- <div
id="ConfluenceContent"><plain-text-body>{scrollbar}</plain-text-body><h2
id="Integrationwithexistingapplications-Integrationwithexistingapplications">Integration
with existing applications</h2><p>You may have an existing JSP (or Struts,
Spring MVC, etc.) application that you want to migrate to Tapestry. It's quite
common to do this in stages, moving some functionality into Tapestry and
leaving other parts, initially, in the other system. <a
href="request-processing-faq.html">You may need to prevent Tapestry from
handling certain requests</a>.</p><h3
id="Integrationwithexistingapplications-HowdoImakeaformonaJSPsubmitintoTapestry?">How
do I make a form on a JSP submit into Tapestry?</h3><p>Tapestry's Form
component does a lot of work while an HTML form is rendering to store all the
information needed to handle the form submission in a later request; this is
all very specific to Tapestry and the particular construction of your pages and
forms; it can't be reproduc
ed from a JSP.</p><p>Fortunately, that isn't necessary: you can have a
standard HTML Form submit to a Tapestry page, you just don't get to use all of
Tapestry's built in conversion and validation logic.</p><p>All you need to know
is how Tapestry converts page class names to page names (that appear in the
URL). It's basically a matter of stripping off the
<em>root-package</em>.<code>pages</code> prefix from the fully qualified class
name. So, for example, if you are building a login screen as a JSP, you might
want to have a Tapestry page to receive the user name and password. Let's
assume the Tapestry page class is
<code>com.example.myapp.pages.LoginForm</code>; the page name will be
<code>loginform (although, since </code><span style="line-height:
1.4285715;">Tapestry is case insensitive, LoginForm would work just as
well)</span><span style="line-height: 1.4285715;">, and the URL will be
</span><code style="line-height: 1.4285715;">/loginform</code><span
style="line-height: 1.4
285715;">.</span></p><p> </p><parameter
ac:name="controls">true</parameter><parameter
ac:name="linenumbers">true</parameter><plain-text-body><form method="post"
action="/loginform">
+ <div id="ConfluenceContent"><h2
id="Integrationwithexistingapplications-Integrationwithexistingapplications">Integration
with existing applications</h2><p>You may have an existing JSP (or Struts,
Spring MVC, etc.) application that you want to migrate to Tapestry. It's quite
common to do this in stages, moving some functionality into Tapestry and
leaving other parts, initially, in the other system. <a
href="integration-with-existing-applications.html">You may need to prevent
Tapestry from handling certain requests</a>.</p><h3
id="Integrationwithexistingapplications-HowdoImakeaformonaJSPsubmitintoTapestry?">How
do I make a form on a JSP submit into Tapestry?</h3><p>Tapestry's Form
component does a lot of work while an HTML form is rendering to store all the
information needed to handle the form submission in a later request; this is
all very specific to Tapestry and the particular construction of your pages and
forms; it can't be reproduced from a JSP.</p><p>Fortunate
ly, that isn't necessary: you can have a standard HTML Form submit to a
Tapestry page, you just don't get to use all of Tapestry's built in conversion
and validation logic.</p><p>All you need to know is how Tapestry converts page
class names to page names (that appear in the URL). It's basically a matter of
stripping off the <em>root-package</em>.<code>pages</code> prefix from the
fully qualified class name. So, for example, if you are building a login screen
as a JSP, you might want to have a Tapestry page to receive the user name and
password. Let's assume the Tapestry page class is
<code>com.example.myapp.pages.LoginForm</code>; the page name will be
<code>loginform (although, since </code><span>Tapestry is case
insensitive, LoginForm would work just as well)</span><span>, and the URL will
be </span><code>/loginform</code><span>.</span></p><p> </p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
+<pre class="brush: java; gutter: true; theme: Default"
style="font-size:12px;"><form method="post" action="/loginform">
<input type="text" value="userName"/>
<br/>
@@ -76,19 +87,24 @@
<input type="submit" value="Login"/>
</form>
-</plain-text-body><p>On the Tapestry side, we can expect that the LoginForm
page will be activated; this means that its activate event handler will be
invoked. We can leverage this, and Tapestry's RequestParameter
annotation:</p><parameter ac:name="controls">true</parameter><parameter
ac:name="linenumbers">true</parameter><plain-text-body>public class LoginForm
+</pre>
+</div></div><p>On the Tapestry side, we can expect that the LoginForm page
will be activated; this means that its activate event handler will be invoked.
We can leverage this, and Tapestry's RequestParameter annotation:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
+<pre class="brush: java; gutter: true; theme: Default"
style="font-size:12px;">public class LoginForm
{
void onActivate(@RequestParameter("userName") String userName,
@RequestParameter("password") String password)
{
// Validate and store credentials, etc.
}
}
-</plain-text-body><p>The RequestParameter annotation extracts the named query
parameter from the request, coerces its type from String to the parameter type
(here, also String) and passes it into the method.</p><h3
id="Integrationwithexistingapplications-HowdoIshareinformationbetweenaJSPapplicationandtheTapestryapplication?">How
do I share information between a JSP application and the Tapestry
application?</h3><p>From the servlet container's point of view, there's no
difference between a servlet, a JSP, and an entire Tapestry application. They
all share the same ServletContext, and (once created), the same
HttpSession.</p><p>On the Tapestry side, it is very easy to read and write
session attributes:</p><parameter ac:name="controls">true</parameter><parameter
ac:name="linenumbers">true</parameter><plain-text-body>public class
ShowSearchResults
+</pre>
+</div></div><p>The RequestParameter annotation extracts the named query
parameter from the request, coerces its type from String to the parameter type
(here, also String) and passes it into the method.</p><h3
id="Integrationwithexistingapplications-HowdoIshareinformationbetweenaJSPapplicationandtheTapestryapplication?">How
do I share information between a JSP application and the Tapestry
application?</h3><p>From the servlet container's point of view, there's no
difference between a servlet, a JSP, and an entire Tapestry application. They
all share the same ServletContext, and (once created), the same
HttpSession.</p><p>On the Tapestry side, it is very easy to read and write
session attributes:</p><div class="code panel pdl" style="border-width:
1px;"><div class="codeContent panelContent pdl">
+<pre class="brush: java; gutter: true; theme: Default"
style="font-size:12px;">public class ShowSearchResults
{
@SessionAttribute
private SearchResults searchResults;
}
-</plain-text-body><p>Reading the instance variable <code>searchResults</code>
is instrumented to instead read the corresponding HttpSession attribute named
"searchResults". You can also specify the <code>value</code> attribute of the
SessionAttribute annotation to override the default attribute
name.</p><p>Writing to the field causes the corresponding HttpSession attribute
to be modified.</p><p>The session is automatically created as needed.</p><h3
id="Integrationwithexistingapplications-HowdoIputtheTapestryapplicationinsideafolder,toavoidconflicts?">How
do I put the Tapestry application inside a folder, to avoid
conflicts?</h3><p>Support for this was added in 5.3; see the notes on the <a
href="configuration.html">configuration
page</a>.</p><plain-text-body>{scrollbar}</plain-text-body><p> </p><p> </p><p> </p></div>
+</pre>
+</div></div><p>Reading the instance variable <code>searchResults</code> is
instrumented to instead read the corresponding HttpSession attribute named
"searchResults". You can also specify the <code>value</code> attribute of the
SessionAttribute annotation to override the default attribute
name.</p><p>Writing to the field causes the corresponding HttpSession attribute
to be modified.</p><p>The session is automatically created as needed.</p><h3
id="Integrationwithexistingapplications-HowdoIputtheTapestryapplicationinsideafolder,toavoidconflicts?">How
do I put the Tapestry application inside a folder, to avoid
conflicts?</h3><p>Support for this was added in 5.3; see the notes on the <a
href="integration-with-existing-applications.html">configuration
page</a>. </p><p> </p><p> </p></div>
</div>
<div class="clearer"></div>
Modified:
websites/production/tapestry/content/ioc-cookbook-basic-services-and-injection.html
==============================================================================
---
websites/production/tapestry/content/ioc-cookbook-basic-services-and-injection.html
(original)
+++
websites/production/tapestry/content/ioc-cookbook-basic-services-and-injection.html
Sat Feb 3 18:21:36 2018
@@ -27,6 +27,16 @@
</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>
+ SyntaxHighlighter.defaults['toolbar'] = false;
+ SyntaxHighlighter.all();
+ </script>
<link href="/styles/style.css" rel="stylesheet" type="text/css"/>
@@ -67,41 +77,16 @@
</div>
<div id="content">
- <div
id="ConfluenceContent"><plain-text-body>{scrollbar}</plain-text-body>
-
-<p>The starting point for Tapestry IOC services and injection is knowing a few
conventions: what to name your classes, what packages to put them in and so
forth.</p>
-
-<p>In many cases, these conventions are just a little stronger: you may have
to do some amount of extra configuration if you choose to go your own way.</p>
-
-<h1 id="IoCCookbook-BasicServicesandInjection-GettingStarted">Getting
Started</h1>
-
-<p>As always, you'll first need to choose a package for your application, such
as org.example.myapp.</p>
-
-<p>By convention, services go in a sub-package named "services". Tapestry IOC
Module class names have a "Module" suffix. Thus, you might start with a module
class org.example.myapp.services.MyAppModule.</p>
-
-<h1 id="IoCCookbook-BasicServicesandInjection-SimpleServices">Simple
Services</h1>
-
-<p>The simplest services don't have any special configuration or dependencies.
They are defined as services so that they can be shared.</p>
-
-<p>For example, the <a class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/services/PropertyAccess.html">PropertyAccess</a>
service is used in multiple places around the framework to access properties
of objects (its a wrapper around the Java Beans Introspector and a bit of
reflection). This is defined in the <a class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/services/TapestryIOCModule.html">TapestryIOCModule</a>.</p>
-
-<p>It's useful to share PropertyAccess, because it does a lot of useful
caching internally.</p>
-
-<p>The PropertyAccess service is defined inside TapestryIOCModule's bind()
method:</p>
-
-<plain-text-body>
- public static void bind(ServiceBinder binder)
+ <div id="ConfluenceContent"><p>The starting point for Tapestry
IOC services and injection is knowing a few conventions: what to name your
classes, what packages to put them in and so forth.</p><p>In many cases, these
conventions are just a little stronger: you may have to do some amount of extra
configuration if you choose to go your own way.</p><h1
id="IoCCookbook-BasicServicesandInjection-GettingStarted">Getting
Started</h1><p>As always, you'll first need to choose a package for your
application, such as org.example.myapp.</p><p>By convention, services go in a
sub-package named "services". Tapestry IOC Module class names have a "Module"
suffix. Thus, you might start with a module class
org.example.myapp.services.MyAppModule.</p><h1
id="IoCCookbook-BasicServicesandInjection-SimpleServices">Simple
Services</h1><p>The simplest services don't have any special configuration or
dependencies. They are defined as services so that they can be
shared.</p><p>For example, the
<a class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/services/PropertyAccess.html">PropertyAccess</a>
service is used in multiple places around the framework to access properties
of objects (its a wrapper around the Java Beans Introspector and a bit of
reflection). This is defined in the <a class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/services/TapestryIOCModule.html">TapestryIOCModule</a>.</p><p>It's
useful to share PropertyAccess, because it does a lot of useful caching
internally.</p><p>The PropertyAccess service is defined inside
TapestryIOCModule's bind() method:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;"> public static void bind(ServiceBinder binder)
{
. . .
binder.bind(PropertyAccess.class, PropertyAccessImpl.class);
binder.bind(ExceptionAnalyzer.class, ExceptionAnalyzerImpl.class);
. . .
- }</plain-text-body>
-
-<p>This example includes <a class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/services/ExceptionAnalyzer.html">ExceptionAnalyzer</a>,
because it has a dependency on PropertyAccess:</p>
-
-<plain-text-body>
-public class ExceptionAnalyzerImpl implements ExceptionAnalyzer
+ }</pre>
+</div></div><p>This example includes <a class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/services/ExceptionAnalyzer.html">ExceptionAnalyzer</a>,
because it has a dependency on PropertyAccess:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;">public class ExceptionAnalyzerImpl implements
ExceptionAnalyzer
{
private final PropertyAccess propertyAccess;
public ExceptionAnalyzerImpl(PropertyAccess propertyAccess)
@@ -110,30 +95,9 @@ public class ExceptionAnalyzerImpl imple
}
. . .
-}</plain-text-body>
-
-<p>And that's the essence of Tapestry IoC right there; the bind() plus the
constructor is <em>all</em> that's necessary.</p>
-
-<h1 id="IoCCookbook-BasicServicesandInjection-ServiceDisambiguation">Service
Disambiguation</h1>
-
-<p>In the previous example, we relied on the fact that only a single service
implements the PropertyAccess interface. Had more than one done so, Tapestry
would have thrown an exception when the ExceptionAnalyzer service was realized
(it isn't until a service is realized that dependencies are resolved).</p>
-
-<p>That's normally okay; in many situations, it makes sense that only a single
service implement a particular interface.</p>
-
-<p>But there are often exceptions to the rule, and in those cases, we must
provide more information to Tapestry when a service is defined, and when it is
injected, in order to disambiguate – to inform Tapestry which particular
version of service to inject.</p>
-
-<p>This example demonstrates a number of ideas that we haven't discussed so
far, so try not to get too distracted by some of the details. One of the main
concepts introduced here is <em>service builder methods</em>. These are
methods, of a Tapestry IoC Module class, that act as an alternate way to define
a service. You often used a service builder method if you are doing more than
simply instantiating a class.</p>
-
-<p>A service builder method is a method of a Module, prefixed with the word
"build". This defines a service, and dependency injection occurs on the
parameters of the service builder method.</p>
-
-<p>The Tapestry web framework includes the concept of an "asset": a resource
that may be inside a web application, or packaged inside a JAR. Assets are
represented as the type <a class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/Asset.html">Asset</a>.</p>
-
-<p>In fact, there are different implementations of this class: one for context
resources (part of the web application), the other for classpath resources
(packaged inside a JAR). The Asset instances are created via <a
class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapesty/services/AssetFactory.html">AssetFactory</a>
services.</p>
-
-<p>Tapestry defines two such services, in the <a class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/services/TapestryModule.html">TapestryModule</a>.</p>
-
-<plain-text-body>
- @Marker(ClasspathProvider.class)
+}</pre>
+</div></div><p>And that's the essence of Tapestry IoC right there; the bind()
plus the constructor is <em>all</em> that's necessary.</p><h1
id="IoCCookbook-BasicServicesandInjection-ServiceDisambiguation">Service
Disambiguation</h1><p>In the previous example, we relied on the fact that only
a single service implements the PropertyAccess interface. Had more than one
done so, Tapestry would have thrown an exception when the ExceptionAnalyzer
service was realized (it isn't until a service is realized that dependencies
are resolved).</p><p>That's normally okay; in many situations, it makes sense
that only a single service implement a particular interface.</p><p>But there
are often exceptions to the rule, and in those cases, we must provide more
information to Tapestry when a service is defined, and when it is injected, in
order to disambiguate – to inform Tapestry which particular version of
service to inject.</p><p>This example demonstrates a number of ideas that we
haven't discu
ssed so far, so try not to get too distracted by some of the details. One of
the main concepts introduced here is <em>service builder methods</em>. These
are methods, of a Tapestry IoC Module class, that act as an alternate way to
define a service. You often used a service builder method if you are doing more
than simply instantiating a class.</p><p>A service builder method is a method
of a Module, prefixed with the word "build". This defines a service, and
dependency injection occurs on the parameters of the service builder
method.</p><p>The Tapestry web framework includes the concept of an "asset": a
resource that may be inside a web application, or packaged inside a JAR. Assets
are represented as the type <a class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/Asset.html">Asset</a>.</p><p>In
fact, there are different implementations of this class: one for context
resources (part of the web application), the other for classpath resources (pa
ckaged inside a JAR). The Asset instances are created via <a
class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapesty/services/AssetFactory.html">AssetFactory</a>
services.</p><p>Tapestry defines two such services, in the <a
class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/services/TapestryModule.html">TapestryModule</a>.</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
+<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;"> @Marker(ClasspathProvider.class)
public AssetFactory buildClasspathAssetFactory(ResourceCache resourceCache,
ClasspathAssetAliasManager aliasManager)
@@ -149,18 +113,9 @@ public class ExceptionAnalyzerImpl imple
public AssetFactory buildContextAssetFactory(ApplicationGlobals globals)
{
return new ContextAssetFactory(request, globals.getContext());
- }</plain-text-body>
-
-<p>Service builder methods are used here for two purposes: For the
ClasspathAssetFactory, we are registering the new service as a listener of
events from another service. For the ContextAssetFactory, we are extracting a
value from an injected service and passing <em>that</em> to the constructor.</p>
-
-<p>What's important is that the services are differentiated not just in terms
of their id (which is defined by the name of the method, after stripping off
"build"), but in terms of their <em>marker annotation</em>.</p>
-
-<p>The <a class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/annotations/Marker.html">Marker</a>
annotation provides the discriminator. When the service type is supplemented
with the ClasspathProvider annotation, the ClasspathAssetFactory is injected.
When the service type is supplemented with the ContextProvider annotation, the
ContextAssetFactory is injected.</p>
-
-<p>Here's an example. Again, we've jumped the gun with this <em>service
contributor method</em> (we'll get into the why and how of these later), but
you can see how Tapestry is figuring out which service to inject based on the
presence of those annotations:</p>
-
-<plain-text-body>
- public void contributeAssetSource(MappedConfiguration<String,
AssetFactory> configuration,
+ }</pre>
+</div></div><p>Service builder methods are used here for two purposes: For the
ClasspathAssetFactory, we are registering the new service as a listener of
events from another service. For the ContextAssetFactory, we are extracting a
value from an injected service and passing <em>that</em> to the
constructor.</p><p>What's important is that the services are differentiated not
just in terms of their id (which is defined by the name of the method, after
stripping off "build"), but in terms of their <em>marker
annotation</em>.</p><p>The <a class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/annotations/Marker.html">Marker</a>
annotation provides the discriminator. When the service type is supplemented
with the ClasspathProvider annotation, the ClasspathAssetFactory is injected.
When the service type is supplemented with the ContextProvider annotation, the
ContextAssetFactory is injected.</p><p>Here's an example. Again, we've jumped
the gun with
this <em>service contributor method</em> (we'll get into the why and how of
these later), but you can see how Tapestry is figuring out which service to
inject based on the presence of those annotations:</p><div class="code panel
pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;"> public void
contributeAssetSource(MappedConfiguration<String, AssetFactory>
configuration,
@ContextProvider
AssetFactory contextAssetFactory,
@@ -169,11 +124,8 @@ public class ExceptionAnalyzerImpl imple
{
configuration.add("context", contextAssetFactory);
configuration.add("classpath", classpathAssetFactory);
- }</plain-text-body>
-
-<p>This is far from the final word on injection and disambiguation; we'll be
coming back to this concept repeatedly. And in later chapters of the cookbook,
we'll also go into more detail about the many other concepts present in this
example. The important part is that Tapestry <em>primarily</em> works off the
parameter type (at the point of injection), but when that is insufficient
(you'll know ... there will be an error) you can provide additional
information, in the form of annotations, to straighten things out.</p>
-
-<plain-text-body>{scrollbar}</plain-text-body></div>
+ }</pre>
+</div></div><p>This is far from the final word on injection and
disambiguation; we'll be coming back to this concept repeatedly. And in later
chapters of the cookbook, we'll also go into more detail about the many other
concepts present in this example. The important part is that Tapestry
<em>primarily</em> works off the parameter type (at the point of injection),
but when that is insufficient (you'll know ... there will be an error) you can
provide additional information, in the form of annotations, to straighten
things out.</p></div>
</div>
<div class="clearer"></div>
Modified:
websites/production/tapestry/content/ioc-cookbook-overriding-ioc-services.html
==============================================================================
---
websites/production/tapestry/content/ioc-cookbook-overriding-ioc-services.html
(original)
+++
websites/production/tapestry/content/ioc-cookbook-overriding-ioc-services.html
Sat Feb 3 18:21:36 2018
@@ -27,6 +27,16 @@
</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>
+ SyntaxHighlighter.defaults['toolbar'] = false;
+ SyntaxHighlighter.all();
+ </script>
<link href="/styles/style.css" rel="stylesheet" type="text/css"/>
@@ -67,12 +77,15 @@
</div>
<div id="content">
- <div
id="ConfluenceContent"><plain-text-body>{scrollbar}</plain-text-body><h1
id="IoCCookbook-OverridingIoCServices-OverridingTapestryIoCServices">Overriding
Tapestry IoC Services</h1><p>Tapestry is designed to be easy to customize, and
the IoC container is the key to that customizability.</p><p>One of Tapestry's
most important activities is resolving injected objects; that is, when Tapestry
is building an object or service and sees a constructor parameter or a field,
it must decide what value to plug in. Most of the time, the injected object is
a service defined elsewhere within the Tapestry IoC container.</p><p>However,
there are cases where you might want to override how Tapestry operates in some
specific way.</p><p>The strategy used to determine what object gets injected is
<a href="injection-in-detail.html">defined inside Tapestry IoC itself</a>;
thus we can take advantage of several features of the Tapestry IoC container in
order to take control over specific
injections.</p><h2
id="IoCCookbook-OverridingIoCServices-ContributingaServiceOverride">Contributing
a Service Override</h2><p>In most cases, services are injected by matching
just the type; there is no @<a class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/annotations/InjectService.html">InjectService</a>
annotation, just a method or constructor parameter whose type matches the
service's interface.</p><p>In this case, it is very easy to supply your own
alternate implementation of a service, by <em>contributing</em><em> a Service
Override</em> in your module class (usually AppModule.java), like
this:</p><parameter ac:name="title">AppModule.java
(partial)</parameter><parameter
ac:name="lang">java</parameter><plain-text-body>
@Contribute(ServiceOverride.class)
+ <div id="ConfluenceContent"><h1
id="IoCCookbook-OverridingIoCServices-OverridingTapestryIoCServices">Overriding
Tapestry IoC Services</h1><p>Tapestry is designed to be easy to customize, and
the IoC container is the key to that customizability.</p><p>One of Tapestry's
most important activities is resolving injected objects; that is, when Tapestry
is building an object or service and sees a constructor parameter or a field,
it must decide what value to plug in. Most of the time, the injected object is
a service defined elsewhere within the Tapestry IoC container.</p><p>However,
there are cases where you might want to override how Tapestry operates in some
specific way.</p><p>The strategy used to determine what object gets injected is
<a href="ioc-cookbook-overriding-ioc-services.html">defined inside Tapestry
IoC itself</a>; thus we can take advantage of several features of the Tapestry
IoC container in order to take control over specific injections.</p><h2
id="IoCCoo
kbook-OverridingIoCServices-ContributingaServiceOverride">Contributing a
Service Override</h2><p>In most cases, services are injected by matching just
the type; there is no @<a class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/annotations/InjectService.html">InjectService</a>
annotation, just a method or constructor parameter whose type matches the
service's interface.</p><p>In this case, it is very easy to supply your own
alternate implementation of a service, by <em>contributing</em><em> a Service
Override</em> in your module class (usually AppModule.java), like this:</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">
+<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;"> @Contribute(ServiceOverride.class)
public static void
setupApplicationServiceOverrides(MappedConfiguration<Class,Object>
configuration)
{
configuration.addInstance(SomeServiceType.class,
SomeServiceTypeOverrideImpl.class);
}
-</plain-text-body><p>The name of the method is not important, as long as the
@<a class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/annotations/Contribute.html">Contribute</a>
annotation is present on the method.</p><p>In this example, we are using
<code>addInstance()</code> which will instantiate the indicated class and
handle dependency resolution. (Be careful with this, because in some cases,
resolving dependencies of the override class can require checking against the
ServiceOverrides service, and you'll get a runtime exception about
ServiceOverrides requiring itself!).</p><p>Sometimes you'll want to define the
override as a service of its own. This is useful if you want to inject a Logger
specific to the service, or if the overriding implementation needs a <a
href="tapestry-ioc-configuration.html">service configuration</a>:</p><parameter
ac:name="title">AppModule.java (partial)</parameter><parameter
ac:name="lang">java</parameter><
plain-text-body> public static void bind(ServiceBinder binder)
+</pre>
+</div></div><p>The name of the method is not important, as long as the @<a
class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/annotations/Contribute.html">Contribute</a>
annotation is present on the method.</p><p>In this example, we are using
<code>addInstance()</code> which will instantiate the indicated class and
handle dependency resolution. (Be careful with this, because in some cases,
resolving dependencies of the override class can require checking against the
ServiceOverrides service, and you'll get a runtime exception about
ServiceOverrides requiring itself!).</p><p>Sometimes you'll want to define the
override as a service of its own. This is useful if you want to inject a Logger
specific to the service, or if the overriding implementation needs a <a
href="ioc-cookbook-overriding-ioc-services.html">service
configuration</a>:</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">
+<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;"> public static void bind(ServiceBinder binder)
{
binder.bind(SomeServiceType.class,
SomeServiceTypeOverrideImpl.class).withId("SomeServiceTypeOverride");
}
@@ -82,11 +95,14 @@
{
configuration.add(SomeServiceType.class, override);
}
-</plain-text-body><p>Here we're defining a service using the module's
<code>bind()</code> method.</p><p>Every service in the IoC container must have
a unique id, that's why we used the <code>withId()</code> method; if we we
hadn't, the default service id would have been "SomeServiceType" which is a
likely conflict with the very service we're trying to override.</p><p>We can
inject our overriding implementation of SomeServiceType using the special @<a
class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/annotations/Local.html">Local</a>
annotation, which indicates that a service within the same module only should
be injected (that is, services of the indicated type in other modules are
ignored). Without @Local, there would be a problem because the override
parameter would need to be resolved using the MasterObjectProvider and,
ultimately, the ServiceOverride service; this would cause Tapestry to throw an
exception indicating that ServiceOverrid
e depends on itself. We defuse that situation by using @Local, which prevents
the MasterObjectProvider service from being used to resolve the override
parameter.</p><h2
id="IoCCookbook-OverridingIoCServices-DecoratingServices">Decorating
Services</h2><p>Another option is to <a
href="tapestry-ioc-decorators.html">decorate</a> the existing service. Perhaps
you want to extend some of the behavior of the service but keep the
rest.</p><p>Alternately, this approach is useful to override a service that is
matched using marker annotations.</p><parameter ac:name="title">AppModule.java
(partial)</parameter><parameter
ac:name="lang">java</parameter><plain-text-body> public SomeServiceType
decorateSomeServiceType(final SomeServiceType delegate)
+</pre>
+</div></div><p>Here we're defining a service using the module's
<code>bind()</code> method.</p><p>Every service in the IoC container must have
a unique id, that's why we used the <code>withId()</code> method; if we we
hadn't, the default service id would have been "SomeServiceType" which is a
likely conflict with the very service we're trying to override.</p><p>We can
inject our overriding implementation of SomeServiceType using the special @<a
class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/annotations/Local.html">Local</a>
annotation, which indicates that a service within the same module only should
be injected (that is, services of the indicated type in other modules are
ignored). Without @Local, there would be a problem because the override
parameter would need to be resolved using the MasterObjectProvider and,
ultimately, the ServiceOverride service; this would cause Tapestry to throw an
exception indicating that ServiceOverride depe
nds on itself. We defuse that situation by using @Local, which prevents the
MasterObjectProvider service from being used to resolve the override
parameter.</p><h2
id="IoCCookbook-OverridingIoCServices-DecoratingServices">Decorating
Services</h2><p>Another option is to <a
href="ioc-cookbook-overriding-ioc-services.html">decorate</a> the existing
service. Perhaps you want to extend some of the behavior of the service but
keep the rest.</p><p>Alternately, this approach is useful to override a service
that is matched using marker annotations.</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">
+<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;"> public SomeServiceType decorateSomeServiceType(final
SomeServiceType delegate)
{
return new SomeServiceType() { . . . };
}
-</plain-text-body><p>This decorate method is invoked because its name matches
the service id of the original service, "SomeServiceType" (you have to adjust
the name to match the service id).</p><p>The method is passed the original
service and its job it to return an <em>interceptor</em>, an object that
implements the same interface, wrapping around the original service. In many
cases, your code will simply re-invoke methods on the delegate, passing the
same parameters. However, an interceptor can decide to not invoke methods, or
it can change parameters, or change return values, or catch or throw
exceptions.</p><p>Note that the object passed in as <code>delegate</code> may
be the core service implementation, or it may be some other interceptor from
some other decorator for the same
service.</p><hr><p> </p><p> </p><plain-text-body>{scrollbar}</plain-text-body></div>
+</pre>
+</div></div><p>This decorate method is invoked because its name matches the
service id of the original service, "SomeServiceType" (you have to adjust the
name to match the service id).</p><p>The method is passed the original service
and its job it to return an <em>interceptor</em>, an object that implements the
same interface, wrapping around the original service. In many cases, your code
will simply re-invoke methods on the delegate, passing the same parameters.
However, an interceptor can decide to not invoke methods, or it can change
parameters, or change return values, or catch or throw exceptions.</p><p>Note
that the object passed in as <code>delegate</code> may be the core service
implementation, or it may be some other interceptor from some other decorator
for the same service.</p><hr><p> </p><p> </p></div>
</div>
<div class="clearer"></div>
Modified: websites/production/tapestry/content/ioc-cookbook-patterns.html
==============================================================================
--- websites/production/tapestry/content/ioc-cookbook-patterns.html (original)
+++ websites/production/tapestry/content/ioc-cookbook-patterns.html Sat Feb 3
18:21:36 2018
@@ -27,6 +27,16 @@
</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>
+ SyntaxHighlighter.defaults['toolbar'] = false;
+ SyntaxHighlighter.all();
+ </script>
<link href="/styles/style.css" rel="stylesheet" type="text/css"/>
@@ -67,11 +77,65 @@
</div>
<div id="content">
- <div
id="ConfluenceContent"><p><plain-text-body>{scrollbar}</plain-text-body>Tapestry
IoC has support for implementing several of the <a class="external-link"
href="http://en.wikipedia.org/wiki/Design_pattern_(computer_science)"
rel="nofollow">Gang Of Four Design Patterns</a>. In fact, the IoC container
itself is a pumped up version of the Factory pattern.</p><parameter
ac:name="style">float:right</parameter><parameter ac:name="title">Related
Articles</parameter><parameter
ac:name="class">aui-label</parameter><rich-text-body><parameter
ac:name="showLabels">false</parameter><parameter
ac:name="showSpace">false</parameter><parameter ac:name="title">Related
Articles</parameter><parameter ac:name="cql">label = "patterns" and space =
currentSpace()</parameter></rich-text-body><p>The basis for these patterns is
often the use of <em>service builder methods</em>, where a <a
href="ioc-cookbook-service-configurations.html">configuration</a> for the
service is combined with a
factory to produce the service implementation on the fly.</p><p><parameter
ac:name="">chainofcommand</parameter></p><h1
id="IoCCookbook-Patterns-ChainofCommandPattern">Chain of Command
Pattern</h1><p>Main Article: <a href="chainbuilder-service.html">Chain of
Command</a></p><p>Let's look at another example, again from the Tapestry code
base. The <a class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/services/InjectionProvider.html">InjectProvider</a>
interface is used to process the @Inject annotation on the fields of a
Tapestry page or component. Many different instances are combined together to
form a <em>chain of command</em>.</p><p>The interface has only a single method
(this is far from uncommon):</p><parameter
ac:name="language">java</parameter><plain-text-body>public interface
InjectionProvider
+ <div id="ConfluenceContent"><p>Tapestry IoC has support for
implementing several of the <a class="external-link"
href="http://en.wikipedia.org/wiki/Design_pattern_(computer_science)"
rel="nofollow">Gang Of Four Design Patterns</a>. In fact, the IoC container
itself is a pumped up version of the Factory pattern.</p><div class="aui-label"
style="float:right" title="Related Articles">
+
+
+
+
+
+
+
+
+<h3>Related Articles</h3>
+
+<ul class="content-by-label"><li>
+ <div>
+ <span class="icon aui-icon aui-icon-small
aui-iconfont-page-default" title="Page">Page:</span> </div>
+
+ <div class="details">
+ <a href="ioc-cookbook-patterns.html">IoC Cookbook -
Patterns</a>
+
+
+ </div>
+ </li><li>
+ <div>
+ <span class="icon aui-icon aui-icon-small
aui-iconfont-page-default" title="Page">Page:</span> </div>
+
+ <div class="details">
+ <a
href="strategybuilder-service.html">StrategyBuilder Service</a>
+
+
+ </div>
+ </li><li>
+ <div>
+ <span class="icon aui-icon aui-icon-small
aui-iconfont-page-default" title="Page">Page:</span> </div>
+
+ <div class="details">
+ <a
href="pipelinebuilder-service.html">PipelineBuilder Service</a>
+
+
+ </div>
+ </li><li>
+ <div>
+ <span class="icon aui-icon aui-icon-small
aui-iconfont-page-default" title="Page">Page:</span> </div>
+
+ <div class="details">
+ <a href="chainbuilder-service.html">ChainBuilder
Service</a>
+
+
+ </div>
+ </li></ul>
+</div>
+
+
+<p>The basis for these patterns is often the use of <em>service builder
methods</em>, where a <a href="ioc-cookbook-patterns.html">configuration</a>
for the service is combined with a factory to produce the service
implementation on the fly.</p><p><span class="confluence-anchor-link"
id="IoCCookbook-Patterns-chainofcommand"></span></p><h1
id="IoCCookbook-Patterns-ChainofCommandPattern">Chain of Command
Pattern</h1><p>Main Article: <a href="ioc-cookbook-patterns.html">Chain of
Command</a></p><p>Let's look at another example, again from the Tapestry code
base. The <a class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/services/InjectionProvider.html">InjectProvider</a>
interface is used to process the @Inject annotation on the fields of a
Tapestry page or component. Many different instances are combined together to
form a <em>chain of command</em>.</p><p>The interface has only a single method
(this is far from uncommon):</p><div class="code p
anel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;">public interface InjectionProvider
{
boolean provideInjection(String fieldName, Class fieldType, ObjectLocator
locator,
ClassTransformation transformation, MutableComponentModel
componentModel);
-}</plain-text-body><p>The return type indicates whether the provider was able
to do something. For example, the AssetInjectionProvider checks to see if
there's an @Path annotation on the field, and if so, converts the path to an
asset, works with the ClassTransformation object to implement injection, and
returns true to indicate success. Returning true terminates the chain early,
and that true value is ultimately returned to the caller.</p><p>In other cases,
it returns false and the chain of command continues down to the next provider.
If no provider is capable of handling the injection, then the value false is
ultimately returned.</p><p>The InjectionProvider service is built up via
contributions. These are the contributions from the
TapestryModule:</p><parameter
ac:name="language">java</parameter><plain-text-body>public static void
contributeInjectionProvider(
+}</pre>
+</div></div><p>The return type indicates whether the provider was able to do
something. For example, the AssetInjectionProvider checks to see if there's an
@Path annotation on the field, and if so, converts the path to an asset, works
with the ClassTransformation object to implement injection, and returns true to
indicate success. Returning true terminates the chain early, and that true
value is ultimately returned to the caller.</p><p>In other cases, it returns
false and the chain of command continues down to the next provider. If no
provider is capable of handling the injection, then the value false is
ultimately returned.</p><p>The InjectionProvider service is built up via
contributions. These are the contributions from the TapestryModule:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
+<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;">public static void contributeInjectionProvider(
OrderedConfiguration<InjectionProvider> configuration,
MasterObjectProvider masterObjectProvider,
ObjectLocator locator,
@@ -88,10 +152,14 @@
configuration.add("Block", new BlockInjectionProvider(), "before:Default");
configuration.add("Service", new ServiceInjectionProvider(locator),
"after:*");
-}</plain-text-body><p>And, of course, other contributions could be made in
other modules ... if you wanted to add in your own form of injection.</p><p>The
configuration is converted into a service via a service builder
method:</p><parameter ac:name="language">java</parameter><plain-text-body>
public InjectionProvider build(List<InjectionProvider> configuration,
ChainBuilder chainBuilder)
+}</pre>
+</div></div><p>And, of course, other contributions could be made in other
modules ... if you wanted to add in your own form of injection.</p><p>The
configuration is converted into a service via a service builder method:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
+<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;"> public InjectionProvider
build(List<InjectionProvider> configuration, ChainBuilder chainBuilder)
{
return chainBuilder.build(InjectionProvider.class, configuration);
- }</plain-text-body><p>Now, let's see how this is used. The InjectWorker
class looks for fields with the InjectAnnotation, and uses the chain of command
to inject the appropriate value. However, to InjectWorker, there is no chain
... just a <em>single</em> object that implements the InjectionProvider
interface.</p><parameter
ac:name="language">java</parameter><plain-text-body>public class InjectWorker
implements ComponentClassTransformWorker
+ }</pre>
+</div></div><p>Now, let's see how this is used. The InjectWorker class looks
for fields with the InjectAnnotation, and uses the chain of command to inject
the appropriate value. However, to InjectWorker, there is no chain ... just a
<em>single</em> object that implements the InjectionProvider interface.</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
+<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;">public class InjectWorker implements
ComponentClassTransformWorker
{
private final ObjectLocator locator;
@@ -134,7 +202,8 @@
}
}
-}</plain-text-body><p>Reducing the chain to a single object vastly simplifies
the code: we've <em>factored out</em> the loop implicit in the chain of
command. That eliminates a lot of code, and that's less code to test, and fewer
paths through InjectWorker, which lowers its complexity further. We don't have
to test the cases where the list of injection providers is empty, or consists
of only a single object, or where it's the third object in that returns true:
it looks like a single object, it acts like a single object ... but its
implementation uses many
objects.<plain-text-body>{scrollbar}</plain-text-body></p></div>
+}</pre>
+</div></div><p>Reducing the chain to a single object vastly simplifies the
code: we've <em>factored out</em> the loop implicit in the chain of command.
That eliminates a lot of code, and that's less code to test, and fewer paths
through InjectWorker, which lowers its complexity further. We don't have to
test the cases where the list of injection providers is empty, or consists of
only a single object, or where it's the third object in that returns true: it
looks like a single object, it acts like a single object ... but its
implementation uses many objects.</p></div>
</div>
<div class="clearer"></div>
Modified:
websites/production/tapestry/content/ioc-cookbook-service-configurations.html
==============================================================================
---
websites/production/tapestry/content/ioc-cookbook-service-configurations.html
(original)
+++
websites/production/tapestry/content/ioc-cookbook-service-configurations.html
Sat Feb 3 18:21:36 2018
@@ -27,6 +27,16 @@
</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>
+ SyntaxHighlighter.defaults['toolbar'] = false;
+ SyntaxHighlighter.all();
+ </script>
<link href="/styles/style.css" rel="stylesheet" type="text/css"/>
@@ -67,62 +77,22 @@
</div>
<div id="content">
- <div
id="ConfluenceContent"><plain-text-body>{scrollbar}</plain-text-body>
-
-<h1 id="IoCcookbook-ServiceConfigurations-ServiceConfigurations">Service
Configurations</h1>
-
-<p>This is an area of Tapestry IoC that is often least well understood.
Tapestry services often must have some configuration to fine tune exactly what
they do. One of the interactions between modules is that these service
configurations are shared: they may be contributed into by any module.</p>
-
-<p>Let's start with the most basic kind, the unordered configuration.</p>
-
-<h1
id="IoCcookbook-ServiceConfigurations-UnorderedServiceConfigurations">Unordered
Service Configurations</h1>
-
-<p>One of Tapestry's features is the ability to package assets (images, style
sheets, JavaScript libraries, etc.) inside JAR files and expose those to the
client. For example, an application URL /assets/org/example/mylib/mylib.js
would refer to a file, myllib.js, stored on the classpath in the
/org/example/mylib folder.</p>
-
-<p>That's fine for most cases, but for certain file extensions, we don't want
to allow a client browser to "troll" for the files, as the contents could
compromise security. For example, downloading a .class file is bad: a clever
client might download one that contains a hard-coded user name or password.</p>
-
-<p>Thus, for certain file extensions, Tapestry guards the resource by
attaching an MD5 digest for the resource to the URL. The checksum is derived
from the file contents; thus it can't be spoofed from the client unless the
client already has the file contents.</p>
-
-<p>This is controlled by the <a class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/services/ResourceDigestGenerator.html">ResourceDigestGenerator</a>
service, which uses its configuration to determine which file extensions
require an MD5 digest.</p>
-
-<h2 id="IoCcookbook-ServiceConfigurations-ContributingtoaService">Contributing
to a Service</h2>
-
-<p>Main Article: <a href="tapestry-ioc-configuration.html">Tapestry IoC
Configuration</a></p>
-
-<p>The Tapestry module makes a contribution into the service configuration:</p>
-
-<parameter ac:name="borderStyle">solid</parameter><plain-text-body>
- public static void
contributeResourceDigestGenerator(Configuration<String> configuration)
+ <div id="ConfluenceContent"><h1
id="IoCcookbook-ServiceConfigurations-ServiceConfigurations">Service
Configurations</h1><p>This is an area of Tapestry IoC that is often least well
understood. Tapestry services often must have some configuration to fine tune
exactly what they do. One of the interactions between modules is that these
service configurations are shared: they may be contributed into by any
module.</p><p>Let's start with the most basic kind, the unordered
configuration.</p><h1
id="IoCcookbook-ServiceConfigurations-UnorderedServiceConfigurations">Unordered
Service Configurations</h1><p>One of Tapestry's features is the ability to
package assets (images, style sheets, JavaScript libraries, etc.) inside JAR
files and expose those to the client. For example, an application URL
/assets/org/example/mylib/mylib.js would refer to a file, myllib.js, stored on
the classpath in the /org/example/mylib folder.</p><p>That's fine for most
cases, but for certain file exte
nsions, we don't want to allow a client browser to "troll" for the files, as
the contents could compromise security. For example, downloading a .class file
is bad: a clever client might download one that contains a hard-coded user name
or password.</p><p>Thus, for certain file extensions, Tapestry guards the
resource by attaching an MD5 digest for the resource to the URL. The checksum
is derived from the file contents; thus it can't be spoofed from the client
unless the client already has the file contents.</p><p>This is controlled by
the <a class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/services/ResourceDigestGenerator.html">ResourceDigestGenerator</a>
service, which uses its configuration to determine which file extensions
require an MD5 digest.</p><h2
id="IoCcookbook-ServiceConfigurations-ContributingtoaService">Contributing to a
Service</h2><p>Main Article: <a
href="ioc-cookbook-service-configurations.html">IoC cookbook - Service Co
nfigurations</a></p><p>The Tapestry module makes a contribution into the
service configuration:</p><div class="code panel pdl" style="border-style:
solid;border-width: 1px;"><div class="codeContent panelContent pdl">
+<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;"> public static void
contributeResourceDigestGenerator(Configuration<String> configuration)
{
configuration.add("class");
configuration.add("tml");
- }</plain-text-body>
-
-<p>This is a <em>service contribution method</em>, a method that is invoked to
provide values for a configuration. We'll see how the service receives these
contributions shortly. The <a class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/Configuration.html">Configuration</a>
object is how values are added to the service's configuration. Other
parameters to a service configuration method are injected much as with a
service's constructor, or a service builder method.</p>
-
-<p>How does Tapestry know which service configuration to update? It's from the
name of the method, anything after the "contribute" prefix is the id of the
service to contribute to (the match against service id is case insensitive).</p>
-
-<p>Here, the configuration receives two values: "class" (a compiled Java
class) and "tml" (a Tapestry component template).</p>
-
-<p>Say your application stored a file on the classpath needed by your
application; for illustrative purposes, perhaps it is a PGP private key. You
don't want any client to able to download a .pgp file, no matter how unlikely
that would be. Thus:</p>
-
-<parameter ac:name="borderStyle">solid</parameter><plain-text-body>
-public class MyAppModule
+ }</pre>
+</div></div><p>This is a <em>service contribution method</em>, a method that
is invoked to provide values for a configuration. We'll see how the service
receives these contributions shortly. The <a class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/Configuration.html">Configuration</a>
object is how values are added to the service's configuration. Other
parameters to a service configuration method are injected much as with a
service's constructor, or a service builder method.</p><p>How does Tapestry
know which service configuration to update? It's from the name of the method,
anything after the "contribute" prefix is the id of the service to contribute
to (the match against service id is case insensitive).</p><p>Here, the
configuration receives two values: "class" (a compiled Java class) and "tml" (a
Tapestry component template).</p><p>Say your application stored a file on the
classpath needed by your application; for illustrative purpos
es, perhaps it is a PGP private key. You don't want any client to able to
download a .pgp file, no matter how unlikely that would be. Thus:</p><div
class="code panel pdl" style="border-style: solid;border-width: 1px;"><div
class="codeContent panelContent pdl">
+<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;">public class MyAppModule
{
public static void
contributeResourceDigestGenerator(Configuration<String> configuration)
{
configuration.add("pgp");
}
-}</plain-text-body>
-
-<p>The contribution in MyAppModule doesn't <em>replace</em> the normal
contribution, it is <em>combined</em>. The end result is that .class, .tml and
.pgp files would <em>all</em> be protected.</p>
-
-<h2 id="IoCcookbook-ServiceConfigurations-ReceivingtheConfiguration">Receiving
the Configuration</h2>
-
-<p>A service receives the configuration as an injected parameter ... not of
type Configuration (that's used for <em>making</em> contributions), but instead
is of type Collection:</p>
-
-<parameter ac:name="borderStyle">solid</parameter><plain-text-body>
-public class ResourceDigestGeneratorImpl implements ResourceDigestGenerator
+}</pre>
+</div></div><p>The contribution in MyAppModule doesn't <em>replace</em> the
normal contribution, it is <em>combined</em>. The end result is that .class,
.tml and .pgp files would <em>all</em> be protected.</p><h2
id="IoCcookbook-ServiceConfigurations-ReceivingtheConfiguration">Receiving the
Configuration</h2><p>A service receives the configuration as an injected
parameter ... not of type Configuration (that's used for <em>making</em>
contributions), but instead is of type Collection:</p><div class="code panel
pdl" style="border-style: solid;border-width: 1px;"><div class="codeContent
panelContent pdl">
+<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;">public class ResourceDigestGeneratorImpl implements
ResourceDigestGenerator
{
private final Set<String> digestExtensions;
@@ -132,22 +102,9 @@ public class ResourceDigestGeneratorImpl
}
. . .
-}</plain-text-body>
-
-<p>In many cases, the configuration is simply stored into an instance
variable; in this example, the value is transformed from a Collection to a
Set.</p>
-
-<p>These kinds of unordered configurations are surprisingly rare in Tapestry
(the only other notable one is for the <a
href="type-coercion.html">TypeCoercer</a> service). However, as you can see,
setting up such a configuration is quite easy.</p>
-
-<h1 id="IoCcookbook-ServiceConfigurations-OrderedConfigurations">Ordered
Configurations</h1>
-
-<p>Ordered configurations are very similar to unordered configurations ... the
difference is that the configuration is provided to the service as a parameter
of type List. This is used when the order of operations counts. Often these
configurations are related to a design pattern such as <a
href="chainbuilder-service.html">Chain of Command</a> or <a
href="pipelinebuilder-service.html">Pipeline</a>.</p>
-
-<p>Here, the example is the <a class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/services/Dispatcher.html">Dispatcher</a>
interface; a Dispatcher inside Tapestry is roughly equivalent to a servlet,
though a touch more active. It is passed a Request and decides if the URL for
the Request is something it can handle; if so it will process the request, send
a response, and return true.</p>
-
-<p>Alternately, if the Request can't be handled, the Dispatcher returns
false.</p>
-
-<parameter ac:name="borderStyle">solid</parameter><plain-text-body>
-public void contributeMasterDispatcher(OrderedConfiguration<Dispatcher>
configuration, . . .)
+}</pre>
+</div></div><p>In many cases, the configuration is simply stored into an
instance variable; in this example, the value is transformed from a Collection
to a Set.</p><p>These kinds of unordered configurations are surprisingly rare
in Tapestry (the only other notable one is for the <a
href="ioc-cookbook-service-configurations.html">TypeCoercer</a> service).
However, as you can see, setting up such a configuration is quite easy.</p><h1
id="IoCcookbook-ServiceConfigurations-OrderedConfigurations">Ordered
Configurations</h1><p>Ordered configurations are very similar to unordered
configurations ... the difference is that the configuration is provided to the
service as a parameter of type List. This is used when the order of operations
counts. Often these configurations are related to a design pattern such as <a
href="ioc-cookbook-service-configurations.html">Chain of Command</a> or <a
href="ioc-cookbook-service-configurations.html">Pipeline</a>.</p><p>Here, the
example is the <a class
="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/services/Dispatcher.html">Dispatcher</a>
interface; a Dispatcher inside Tapestry is roughly equivalent to a servlet,
though a touch more active. It is passed a Request and decides if the URL for
the Request is something it can handle; if so it will process the request, send
a response, and return true.</p><p>Alternately, if the Request can't be
handled, the Dispatcher returns false.</p><div class="code panel pdl"
style="border-style: solid;border-width: 1px;"><div class="codeContent
panelContent pdl">
+<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;">public void
contributeMasterDispatcher(OrderedConfiguration<Dispatcher>
configuration, . . .)
{
// Looks for the root path and renders the start page
@@ -164,40 +121,14 @@ public void contributeMasterDispatcher(O
configuration.add("PageRender", new PageRenderDispatcher(. . .));
configuration.add("ComponentAction", new ComponentActionDispatcher(. . .),
"after:PageRender");
-}</plain-text-body>
-
-<p>With an <a class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/OrderedConfiguration.html">OrderedConfiguration</a>,
each contribution gets a name, which must be unique. Here the names are
RootPath, Asset, PageRender and ComponentAction.</p>
-
-<p>The add() method takes a name, the contributed object for that name, and
then zero or more optional constraints. The constraints control the ordering.
The "after:" constraint ensures that the contribution is ordered after the
other named contribution, the "before:" contribution is the opposite.</p>
-
-<p>The ordering occurs on the complete set of contributions, from all
modules.</p>
-
-<p>Here, we need a specific order, used to make sure that the Dispatchers
don't get confused about which URLs are appropriate ... for example, an asset
URL might be /assets/tapestry5/tapestry.js. This looks just like a component
action URL (for page "assets/tapestry5/tapestry" and component "js"). Given
that software is totally lacking in basic common-sense, we instead use careful
ordering of the Dispatchers to ensure that AssetDispatcher is checked
<em>before</em> the ComponentAction dispatcher.</p>
-
-<h2
id="IoCcookbook-ServiceConfigurations-ReceivingtheConfiguration.1">Receiving
the Configuration</h2>
-
-<p>The configuration, once assembled and ordered, is provided as a List.</p>
-
-<p>The MasterDispatcher service configuration defines a <a
href="chainbuilder-service.html">Chain of Command</a> and we can provide the
implementation using virtually no code:</p>
-
-<parameter ac:name="borderStyle">solid</parameter><plain-text-body>
- public static Dispatcher buildMasterDispatcher(List<Dispatcher>
configuration, ChainBuilder chainBuilder)
+}</pre>
+</div></div><p>With an <a class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/OrderedConfiguration.html">OrderedConfiguration</a>,
each contribution gets a name, which must be unique. Here the names are
RootPath, Asset, PageRender and ComponentAction.</p><p>The add() method takes a
name, the contributed object for that name, and then zero or more optional
constraints. The constraints control the ordering. The "after:" constraint
ensures that the contribution is ordered after the other named contribution,
the "before:" contribution is the opposite.</p><p>The ordering occurs on the
complete set of contributions, from all modules.</p><p>Here, we need a specific
order, used to make sure that the Dispatchers don't get confused about which
URLs are appropriate ... for example, an asset URL might be
/assets/tapestry5/tapestry.js. This looks just like a component action URL (for
page "assets/tapestry5/tapestry" and component "js"). Given that sof
tware is totally lacking in basic common-sense, we instead use careful
ordering of the Dispatchers to ensure that AssetDispatcher is checked
<em>before</em> the ComponentAction dispatcher.</p><h2
id="IoCcookbook-ServiceConfigurations-ReceivingtheConfiguration.1">Receiving
the Configuration</h2><p>The configuration, once assembled and ordered, is
provided as a List.</p><p>The MasterDispatcher service configuration defines a
<a href="ioc-cookbook-service-configurations.html">Chain of Command</a> and we
can provide the implementation using virtually no code:</p><div class="code
panel pdl" style="border-style: solid;border-width: 1px;"><div
class="codeContent panelContent pdl">
+<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;"> public static Dispatcher
buildMasterDispatcher(List<Dispatcher> configuration, ChainBuilder
chainBuilder)
{
return chainBuilder.build(Dispatcher.class, configuration);
- }</plain-text-body>
-
-<p><a class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/services/ChainBuilder.html">ChainBuilder</a>
is a service that <em>builds other services</em>. Here it creates an object of
type Dispatcher in terms of the list of Dispatchers. This is one of the most
common uses of service builder methods ... for when the service implementation
doesn't exist, but can be constructed at runtime.</p>
-
-<h1 id="IoCcookbook-ServiceConfigurations-MappedConfigurations">Mapped
Configurations</h1>
-
-<p>The last type of service configuration is the mapped service configuration.
Here we relate a key, often a string, to some value. The contributions are
ultimately combined to form a Map.</p>
-
-<p>Tapestry IoC's <a href="symbols.html">symbol</a> mechanism allows
configuration values to be defined and perhaps overridden, then provided to
services via injection, using the @<a class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/annotations/Value.html">Value</a>
annotation.</p>
-
-<p>The first step is to contribute values.</p>
-
-<parameter ac:name="borderStyle">solid</parameter><plain-text-body>
- public static void contributeFactoryDefaults(MappedConfiguration<String,
String> configuration)
+ }</pre>
+</div></div><p><a class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/services/ChainBuilder.html">ChainBuilder</a>
is a service that <em>builds other services</em>. Here it creates an object of
type Dispatcher in terms of the list of Dispatchers. This is one of the most
common uses of service builder methods ... for when the service implementation
doesn't exist, but can be constructed at runtime.</p><h1
id="IoCcookbook-ServiceConfigurations-MappedConfigurations">Mapped
Configurations</h1><p>The last type of service configuration is the mapped
service configuration. Here we relate a key, often a string, to some value. The
contributions are ultimately combined to form a Map.</p><p>Tapestry IoC's <a
href="ioc-cookbook-service-configurations.html">symbol</a> mechanism allows
configuration values to be defined and perhaps overridden, then provided to
services via injection, using the @<a class="external-link"
href="http://tapestry.apache.org
/current/apidocs/org/apache/tapestry5/ioc/annotations/Value.html">Value</a>
annotation.</p><p>The first step is to contribute values.</p><div class="code
panel pdl" style="border-style: solid;border-width: 1px;"><div
class="codeContent panelContent pdl">
+<pre class="brush: java; gutter: false; theme: Default"
style="font-size:12px;"> public static void
contributeFactoryDefaults(MappedConfiguration<String, String>
configuration)
{
configuration.add(SymbolConstants.FILE_CHECK_INTERVAL, "1000"); // 1 second
configuration.add(SymbolConstants.FILE_CHECK_UPDATE_TIMEOUT, "50"); // 50
milliseconds
@@ -210,13 +141,8 @@ public void contributeMasterDispatcher(O
"org/apache/tapestry5/scriptaculous_1_7_1_beta_3");
configuration.add("tapestry.jscalendar.path",
"org/apache/tapestry5/jscalendar-1.0");
configuration.add("tapestry.jscalendar",
"classpath:${tapestry.jscalendar.path}");
- }</plain-text-body>
-
-<p>These contribution set up a number of defaults used to configure various
Tapestry services. As you can see, you can even define symbol values in terms
of other symbol values.</p>
-
-<p>Mapped configurations don't have to be keyed on Strings (enums or Class are
other common key types). When a mapped configuration <em>is</em> keyed on
String, then a case-insensitive map is used.</p>
-
-<plain-text-body>{scrollbar}</plain-text-body></div>
+ }</pre>
+</div></div><p>These contribution set up a number of defaults used to
configure various Tapestry services. As you can see, you can even define symbol
values in terms of other symbol values.</p><p>Mapped configurations don't have
to be keyed on Strings (enums or Class are other common key types). When a
mapped configuration <em>is</em> keyed on String, then a case-insensitive map
is used.</p></div>
</div>
<div class="clearer"></div>
Modified: websites/production/tapestry/content/ioc-cookbook.html
==============================================================================
--- websites/production/tapestry/content/ioc-cookbook.html (original)
+++ websites/production/tapestry/content/ioc-cookbook.html Sat Feb 3 18:21:36
2018
@@ -27,6 +27,16 @@
</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>
+ SyntaxHighlighter.defaults['toolbar'] = false;
+ SyntaxHighlighter.all();
+ </script>
<link href="/styles/style.css" rel="stylesheet" type="text/css"/>
@@ -67,7 +77,58 @@
</div>
<div id="content">
- <div
id="ConfluenceContent"><p><plain-text-body>{scrollbar}</plain-text-body></p><parameter
ac:name="hidden">true</parameter><parameter
ac:name="atlassian-macro-output-type">BLOCK</parameter><rich-text-body><p>A
tutorial for using Tapestry's Inversion of Control
container</p></rich-text-body><p>Tapestry <strong>Inversion of Control</strong>
(IoC), though originally designed specifically for the needs of the Tapestry
web framework, may also be employed as a stand-alone IoC container, separate
from the rest of Tapestry.</p><parameter
ac:name="style">float:right</parameter><parameter ac:name="title">Related
Articles</parameter><parameter
ac:name="class">aui-label</parameter><rich-text-body><parameter
ac:name="showLabels">false</parameter><parameter
ac:name="showSpace">false</parameter><parameter ac:name="title">Related
Articles</parameter><parameter ac:name="cql">label = "ioc" and space =
currentSpace()</parameter></rich-text-body><p>Tapestry IoC is a sophisticated
tool
that takes some experience to use properly.</p><p>The IOC documentation in
the User Guide is factually correct, but it is designed more as a reference,
rather than giving the big picture. In this Cookbook, we'll show a bit more
about how to use Tapestry IoC, using real examples from the Tapestry code base
(both the tapestry-ioc and tapestry-core modules).</p><p>A word of caution:
several of the examples have been taken from Tapestry's <em>internal</em> code
base. Tapestry internals are private, subject to change at any time, so be
aware that if you go peeking at the internal source code, it may have changed
since the corresponding documentation was
written.</p><p><strong>Contents:</strong></p><ul><li><a
href="ioc-cookbook-basic-services-and-injection.html">Basic Services and
Injection</a></li><li><a
href="ioc-cookbook-overriding-ioc-services.html">Overriding Tapestry IoC
Services</a></li><li><a href="ioc-cookbook-patterns.html">Using
Patterns</a></li><li><a href="ioc-cookbook-s
ervice-configurations.html">Service Configurations</a></li></ul></div>
+ <div id="ConfluenceContent"><p>Tapestry <strong>Inversion of
Control</strong> (IoC), though originally designed specifically for the needs
of the Tapestry web framework, may also be employed as a stand-alone IoC
container, separate from the rest of Tapestry.</p><div class="aui-label"
style="float:right" title="Related Articles">
+
+
+
+
+
+
+
+
+<h3>Related Articles</h3>
+
+<ul class="content-by-label"><li>
+ <div>
+ <span class="icon aui-icon aui-icon-small
aui-iconfont-page-default" title="Page">Page:</span> </div>
+
+ <div class="details">
+ <a href="ioc.html">IOC</a>
+
+
+ </div>
+ </li><li>
+ <div>
+ <span class="icon aui-icon aui-icon-small
aui-iconfont-page-default" title="Page">Page:</span> </div>
+
+ <div class="details">
+ <a href="ioc-cookbook.html">IoC cookbook</a>
+
+
+ </div>
+ </li><li>
+ <div>
+ <span class="icon aui-icon aui-icon-small
aui-iconfont-page-default" title="Page">Page:</span> </div>
+
+ <div class="details">
+ <a href="tapestry-ioc-overview.html">Tapestry IoC
Overview</a>
+
+
+ </div>
+ </li><li>
+ <div>
+ <span class="icon aui-icon aui-icon-small
aui-iconfont-page-default" title="Page">Page:</span> </div>
+
+ <div class="details">
+ <a
href="tapestry-inversion-of-control-faq.html">Tapestry Inversion of Control
FAQ</a>
+
+
+ </div>
+ </li></ul>
+</div>
+
+
+<p>Tapestry IoC is a sophisticated tool that takes some experience to use
properly.</p><p>The IOC documentation in the User Guide is factually correct,
but it is designed more as a reference, rather than giving the big picture. In
this Cookbook, we'll show a bit more about how to use Tapestry IoC, using real
examples from the Tapestry code base (both the tapestry-ioc and tapestry-core
modules).</p><p>A word of caution: several of the examples have been taken from
Tapestry's <em>internal</em> code base. Tapestry internals are private, subject
to change at any time, so be aware that if you go peeking at the internal
source code, it may have changed since the corresponding documentation was
written.</p><p><strong>Contents:</strong></p><ul><li><a
href="ioc-cookbook-basic-services-and-injection.html">Basic Services and
Injection</a></li><li><a
href="ioc-cookbook-overriding-ioc-services.html">Overriding IoC
Services</a></li><li><a href="ioc-cookbook-patterns.html">Using Patterns</a></l
i><li><a href="ioc-cookbook-service-configurations.html">Service
Configurations</a></li></ul></div>
</div>
<div class="clearer"></div>
Modified: websites/production/tapestry/content/javascript-faq.html
==============================================================================
--- websites/production/tapestry/content/javascript-faq.html (original)
+++ websites/production/tapestry/content/javascript-faq.html Sat Feb 3
18:21:36 2018
@@ -27,6 +27,16 @@
</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>
+ SyntaxHighlighter.defaults['toolbar'] = false;
+ SyntaxHighlighter.all();
+ </script>
<link href="/styles/style.css" rel="stylesheet" type="text/css"/>
@@ -67,7 +77,7 @@
</div>
<div id="content">
- <div
id="ConfluenceContent"><plain-text-body>{scrollbar}</plain-text-body><h2
id="JavaScriptFAQ-JavaScript">JavaScript</h2><p>Main article: <a
href="legacy-javascript.html">Legacy JavaScript</a></p><h3
id="JavaScriptFAQ-WhydoIgeta"Tapestryisundefined"erroronformsubmit?(5.3andearlier)">Why
do I get a "Tapestry is undefined" error on form submit? (5.3 and
earlier)</h3><p>This client-side error is clear but can be awkward to solve. It
means your browser has not been able to load the tapestry.js file properly. The
question is, why? It can be due to multiple reasons, some of them
below:</p><ul><li>First, check if 'tapestry.js' is present in the head part of
your resulting HTML page.</li><li><p>If you have set the <a
class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/SymbolConstants.html#COMBINE_SCRIPTS">tapestry.combine-scripts</a>
configuration symbol to true, Tapestry generates one single URL to retrieve
all the JS fi
les. Sometimes, this can produce long URLs that browsers are unable to
retrieve. Try setting the symbol to false.</p><rich-text-body><p>This only
applies to Tapestry 5.1.</p></rich-text-body></li><li>If you have included
jQuery in conjunction with Tapestry's prototype, that will cause a conflict
with the '$' selector used by both. In this case, you should put jQuery on top
of the stack and turn on the <a class="external-link"
href="http://api.jquery.com/jQuery.noConflict/"
rel="nofollow">jQuery.noConflict</a> mode.</li><li>Also, if you have included a
custom or third-party JS library on top of the stack that causes the JavaScript
parsing to fail, then check the JavaScript syntax in that library.</li><li>If
you have used a tool to minimize your JavaScript libraries, this can lead to
JavaScript syntax errors, so check if it works with all the JavaScript files
unpacked.</li></ul><h3
id="JavaScriptFAQ-What'sthedifferencebetweentheT5objectandtheTapestryobjectinthebrowser?(5.3andearlier)
">What's the difference between the <code>T5</code> object and the
<code>Tapestry</code> object in the browser? (5.3 and earlier)</h3><p>Both of
these objects are <em>namespaces</em>: containers of functions, constants, and
nested namespaces.</p><p>The <code>T5</code> object is a replacement for the
<code>Tapestry</code> object, starting in release 5.3. Increasingly, functions
defined by the <code>Tapestry</code> object are being replaced with similar or
equivalent functions in the <code>T5</code> object.</p><p>This is part of an
overall goal, spanning at least two releases of Tapestry, to make Tapestry
JavaScript framework agnostic; which is to say, not depend specifically on
Prototype or jQuery. Much of the code in the <code>Tapestry</code> object is
specifically linked to Prototype and Scriptaculous.</p><p>The <code>T5</code>
object represents a stable, documented, set of APIs that are preferred when
building components for maximum portability between underlying JavaScript framew
orks. In other words, when building component libraries, coding to the
<code>T5</code> object ensures that your component will be useful regardless of
whether the final application is built using Prototype, jQuery or something
else.</p></div>
+ <div id="ConfluenceContent"><h2
id="JavaScriptFAQ-JavaScript">JavaScript</h2><p>Main article: <a
href="javascript-faq.html">JavaScript FAQ</a></p><h3
id="JavaScriptFAQ-WhydoIgeta"Tapestryisundefined"erroronformsubmit?(5.3andearlier)">Why
do I get a "Tapestry is undefined" error on form submit? (5.3 and
earlier)</h3><p>This client-side error is clear but can be awkward to solve. It
means your browser has not been able to load the tapestry.js file properly. The
question is, why? It can be due to multiple reasons, some of them
below:</p><ul><li>First, check if 'tapestry.js' is present in the head part of
your resulting HTML page.</li><li><p>If you have set the <a
class="external-link"
href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/SymbolConstants.html#COMBINE_SCRIPTS">tapestry.combine-scripts</a>
configuration symbol to true, Tapestry generates one single URL to retrieve
all the JS files. Sometimes, this can produce long URLs that brow
sers are unable to retrieve. Try setting the symbol to false.</p><div
class="confluence-information-macro confluence-information-macro-note"><span
class="aui-icon aui-icon-small aui-iconfont-warning
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>This only applies to Tapestry
5.1.</p></div></div></li><li>If you have included jQuery in conjunction with
Tapestry's prototype, that will cause a conflict with the '$' selector used by
both. In this case, you should put jQuery on top of the stack and turn on the
<a class="external-link" href="http://api.jquery.com/jQuery.noConflict/"
rel="nofollow">jQuery.noConflict</a> mode.</li><li>Also, if you have included a
custom or third-party JS library on top of the stack that causes the JavaScript
parsing to fail, then check the JavaScript syntax in that library.</li><li>If
you have used a tool to minimize your JavaScript libraries, this can lead to
JavaScript syntax errors, so check if it works with a
ll the JavaScript files unpacked.</li></ul><h3
id="JavaScriptFAQ-What'sthedifferencebetweentheT5objectandtheTapestryobjectinthebrowser?(5.3andearlier)">What's
the difference between the <code>T5</code> object and the
<code>Tapestry</code> object in the browser? (5.3 and earlier)</h3><p>Both of
these objects are <em>namespaces</em>: containers of functions, constants, and
nested namespaces.</p><p>The <code>T5</code> object is a replacement for the
<code>Tapestry</code> object, starting in release 5.3. Increasingly, functions
defined by the <code>Tapestry</code> object are being replaced with similar or
equivalent functions in the <code>T5</code> object.</p><p>This is part of an
overall goal, spanning at least two releases of Tapestry, to make Tapestry
JavaScript framework agnostic; which is to say, not depend specifically on
Prototype or jQuery. Much of the code in the <code>Tapestry</code> object is
specifically linked to Prototype and Scriptaculous.</p><p>The <code>T5</code>
object
represents a stable, documented, set of APIs that are preferred when building
components for maximum portability between underlying JavaScript frameworks. In
other words, when building component libraries, coding to the <code>T5</code>
object ensures that your component will be useful regardless of whether the
final application is built using Prototype, jQuery or something else.</p></div>
</div>
<div class="clearer"></div>