You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by bu...@apache.org on 2020/04/26 21:22:57 UTC
svn commit: r1059832 [8/15] - in /websites/production/tapestry/content: ./
books.data/ cache/ indexv2-old.data/ this-page-has-been-deleted.data/
Modified: websites/production/tapestry/content/injection-in-detail.html
==============================================================================
--- websites/production/tapestry/content/injection-in-detail.html (original)
+++ websites/production/tapestry/content/injection-in-detail.html Sun Apr 26 21:22:55 2020
@@ -84,41 +84,52 @@
+
+
<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>
+ <span class="icon aui-icon content-type-page" title="Page">Page:</span> </div>
<div class="details">
- <a href="injection-in-detail.html">Injection in Detail</a>
+ <a href="environmental-services.html">Environmental Services</a>
</div>
</li><li>
<div>
- <span class="icon aui-icon aui-icon-small aui-iconfont-page-default" title="Page">Page:</span> </div>
+ <span class="icon aui-icon content-type-page" title="Page">Page:</span> </div>
<div class="details">
- <a href="injection-faq.html">Injection FAQ</a>
+ <a href="injection-in-detail.html">Injection in Detail</a>
</div>
</li><li>
<div>
- <span class="icon aui-icon aui-icon-small aui-iconfont-page-default" title="Page">Page:</span> </div>
+ <span class="icon aui-icon content-type-page" title="Page">Page:</span> </div>
<div class="details">
<a href="injection.html">Injection</a>
</div>
+ </li><li>
+ <div>
+ <span class="icon aui-icon content-type-page" title="Page">Page:</span> </div>
+
+ <div class="details">
+ <a href="injection-faq.html">Injection FAQ</a>
+
+
+ </div>
</li></ul>
</div>
<p>Despite this, injection generally <em>Just Works</em>: most of the time, you want Tapestry to inject a service, and only a single service implements the service interface.</p><p>This document discusses what to do when you hit a case that doesn't Just Work, or when you want to extend the injection logic in some way.</p><p>Some aspects of this discussion reflect Tapestry IoC used within a Tapestry web application: the tapestry-core module makes some extensions to injection.</p><h1 id="InjectioninDetail-InjectionTriggers">Injection Triggers</h1><p>Injection is triggered in a number of ways:</p><ul><li>A field in a component class, autobuilt object, or service implementation class is annotated with @Inject.</li><li>A method parameter to a service builder method, a decorator method, or a contribute method (in a Tapestry IoC module class).</li><li>A constructor parameter to an autobuilt object, or a service implementation class.</li><li>Any of the above with an @InjectService annotatio
n.</li></ul><p>These define the <em>point of injection</em>.</p><p>Injection also covers a related matter: providing special resources to a service or component (remember that pages are specialized components). For a service, the service's id (as a string) or extensible configuration (as a Collection, List or Map) may be provided. For a component, the component's id, locale, message catalog, or component resources may be provided.</p><h1 id="InjectioninDetail-StandardInjectionProcessing">Standard Injection Processing</h1><p>This section describes standard injection, which applies at the IoC layer: autobuilt objects and service implementations. The steps for injection into Tapestry components are slightly different and are covered later.</p><p>So a the point of injection, Tapestry has identified a field or parameter that should be injected. At this point, Tapestry knows the following:</p><ul><li>The field name (if field injection). The parameter name is not available.</li><li>Th
e field or parameter type, as a Java class. In many cases, this will be enough to identify what object shall be injected.</li><li>Any additional annotations on the field or parameter.</li></ul><p>Tapestry proceeds with this information.</p><h2 id="InjectioninDetail-Checkfor@InjectService">Check for @InjectService</h2><p>Tapestry checks first for the @InjectService annotation. The value of this annotation is the service id to inject. When @InjectService is present at the point of injection, the search is complete, though the injection can fail (throwing an exception) if the service id indicated does not exist, or if the service's interface is not compatible with the field's type.</p><h2 id="InjectioninDetail-Checkforserviceresources">Check for service resources</h2><p>This step applies only to IoC layer injection (not to injection into components).</p><p>When the @Inject annotation is <em>not present</em> at the point of injection, Tapestry checks to see if a resource can be injected
. Services are global values, but resources are specific to the service under construction.</p><p>When the Inject annotation is present, this step is skipped (this is necessary when the object to be injected has a type that conflicts with a resource type, such as List or Class).</p><ul><li>org.slf4j.Logger – The Logger of the service being constructed (or the logger of the Module class being instantiated).</li><li><a class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/ObjectLocator.html">ObjectLocator</a> – For contribute methods, used to locate additional objects.</li><li><a class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/ServiceResources.html">ServiceResources</a> – For service builder methods, an extended version of ObjectLocator. </li><li>Class – The service interface type.</li><li><a class="external-link" href="http://tapestry.apache.org/current/apido
cs/org/apache/tapestry5/ioc/OperationTracker.html">OperationTracker</a> – Used to track deeply nested operations so that errors can be reported sensibly.</li><li>Object, or service interface type – Passed to decorator methods.</li><li>Collection, List, Map – Assembled service configurations passed to service builder methods (or service class constructors).</li><li><p>Configuration, OrderedConfiguration, MappedConfiguration – Configuration passed to contribute methods, to build service configurations. <br clear="none" class="atl-forced-newline"> <br clear="none" class="atl-forced-newline"> If field type does not match any of the available resource types, or the Inject annotation is present, logic continues to the next step.</p><div class="confluence-information-macro confluence-information-macro-warning"><span class="aui-icon aui-icon-small aui-iconfont-error confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>Injection
of resources into fields is triggered by the presence of the @<a class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/annotations/InjectResource.html">InjectResource</a> annotation, whereas injection of resources into parameters occurs when the Inject or InjectService annotation is <em>not</em> present. These rules are slightly tricky, which reflects a desire to avoid any annotations except when needed, and the fact that field injection came much later than parameter injection.</p></div></div></li></ul><h2 id="InjectioninDetail-ServiceLookupbyTypeandAnnotations">Service Lookup by Type and Annotations</h2><p>Tapestry attempts to find a matching <em>service</em>.</p><p>First, it generates a set of services whose service interface is compatible with the injection type. This is based on assignability.</p><p>If the @<a class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/annotations/Local.html">Local<
/a> annotation is present, then services not from the module containing the service being constructed will be eliminated.</p><p>Tapestry then works through the known marker annotations. For each marker annotation that is present at the point of injection, Tapestry eliminates services which <em>do not</em> have the marker. Thus, if multiple marker annotations are present, the final service must have <em>all of them</em>.</p><p>At the end, of this, Tapestry determines how many services match.</p><ul><li>If there is a single matching service, then the service to inject as been identified.</li><li>If there are no matches, and there were no marker annotations at the point of injection, then the Tapestry continues to the next step.</li><li>Otherwise there were either no matches, or too many matches: Tapestry will throw a RuntimeException.</li></ul><h2 id="InjectioninDetail-MasterObjectProviderLookup">MasterObjectProvider Lookup</h2><p>This is the point at which Tapestry's extensibility co
mes into play. MasterObjectProvider is a service, with a configuration of <a class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/ObjectProvider.html">ObjectProviders</a>.</p><p>The MasterObjectProvider is also the point at which Tapestry's IoC layer injection, and Tapestry's component injection, unite.</p><p>As a chain-of-command, each of the following ObjectProviders will be considered and will attempt to identify the object to be injected.</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 class="confluence-link">A common problem when extending injection is that contributions into the MasterObjectProvider configuration have to be handled carefully. Any dependencies of the contributed objects should be resolvable using only the early stages of the injection proce
ss, otherwise MasterObjectProvider will have to be instantiated in order to handle its own injection: Tapestry will detect this impossibility and throw an exception. In addition, the <a href="typecoercer-service.html">TypeCoercer Service</a> is used by several ObjectProvider implementations, so the same restrictions apply to TypeCoercer service contributions.</p></div></div><h3 id="InjectioninDetail-ValueObjectProvider">Value ObjectProvider</h3><p>Checks for the presence of the @<a class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/annotations/Value.html">Value</a> annotation. If present, then the annotation's value is evaluated (to expand any symbol references), and the TypeCoercer service is used to convert the resulting String to the injection type (the field or parameter type).</p><h3 id="InjectioninDetail-SymbolObjectProvider">Symbol ObjectProvider</h3><p>Similar to the Value ObjectProvider: the @<a class="external-link" href
="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/annotations/Symbol.html">Symbol</a> annotation's value (if present) is looked up using the <a class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/services/SymbolSource.html">SymbolSource</a> service, and converted to the injection type via the TypeCoercer service.</p><h3 id="InjectioninDetail-AutobuildObjectProvider">Autobuild ObjectProvider</h3><p>Checks to see if the @<a class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/annotations/Autobuild.html">Autobuild</a> annotation is present and, if so, autobuilds the value for the parameter. Of course, the object being built will itself be configured via injection.</p><h3 id="InjectioninDetail-ServiceOverrideObjectProvider">ServiceOverride ObjectProvider</h3><p>Checks any contributions to the <a class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apac
he/tapestry5/ioc/services/ServiceOverride.html">ServiceOverride</a> service. Contributions map a type to an object of that type. Thus, ServiceOverrides will override injections of services that are not qualified with a marker annotation.</p><h3 id="InjectioninDetail-AliasObjectProvider(tapestry-core)">Alias ObjectProvider (tapestry-core)</h3><p>Uses the Alias service (<a class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/services/Alias.html">API</a>) to look for an object that can be injected.</p><div class="confluence-information-macro confluence-information-macro-warning"><span class="aui-icon aui-icon-small aui-iconfont-error confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>Deprecated in Tapestry 5.2 and removed in 5.4.</p></div></div><p>This is commonly used to override a built-in service by contributing an object with the exact same interface. This is an older and more complex version of the Se
rviceOverride provider.</p><h3 id="InjectioninDetail-AssetObjectProvider(tapestry-core)">Asset ObjectProvider (tapestry-core)</h3><p>Checks for the @<a class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/annotations/Path.html">Path</a> annotation.</p><p>If present, the annotation's value has embedded symbols expanded, and is converted into an Asset (which must exist).</p><p>The TypeCoercer can then convert the Asset to the injection type, for example, as Resource.</p><h3 id="InjectioninDetail-ServiceObjectProvider(tapestry-core)">Service ObjectProvider (tapestry-core)</h3><p>Looks for the @<a class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/annotations/Service.html">Service</a> annotation; if present, the annotation's value is the exact service id to inject. This is necessary because injections into <em>component</em> fields are always triggered by the Inject annotation.</p><div class="confluence-in
formation-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 is supported but no longer necessary, as the @InjectService annotation is now also supported for component fields.</p></div></div><h3 id="InjectioninDetail-SpringBeanObjectProvider(tapestry-spring)">SpringBean ObjectProvider (tapestry-spring)</h3><p>Attempts to resolve a Spring bean purely by object type (Spring qualifiers are not supported). If no beans are assignable to the type, then processing continues. If exactly one is assignable, it is used as the injection value. If more than one bean is assignable, it is an error (and a list of matching beans names will be part of the thrown exception).</p><h2 id="InjectioninDetail-ServiceLookup">Service Lookup</h2><p>If none of the ObjectProviders can identify the value to inject, a last step occurs: lookup by service type. If exactly <
em>one</em> service matches the injection type, then that service is injected.</p><p>Otherwise, the lookup fails because either no services match, or more than one matches. An exception will be thrown with the details, including a list of matching services (if there is more than one match).</p><h1 id="InjectioninDetail-Post-InjectionMethods">Post-Injection Methods</h1><p>Autobuilt objects (services and the like, but <em>not</em> components) may have post-injection methods.</p><p>Any public method may have the @<a class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/annotations/PostInjection.html">PostInjection</a> annotation.</p><p>Such methods are invoked after constructor and/or field injection. Only <strong>public methods</strong> will be invoked. Any return value is ignored.</p><p>The method often takes no parameters; however if the method has parameters, these parameters are new points of injection.</p><p>Often this is used to perform add
itional setup, such as registerring a service as a listener of events produced by another service:</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 MyServiceImpl implements MyService, UpdateListener
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java; gutter: false; theme: Default" data-theme="Default">public class MyServiceImpl implements MyService, UpdateListener
{
@PostInjection
public void registerAsListener(UpdateListenerHub hub)
Modified: websites/production/tapestry/content/integrating-with-jpa.html
==============================================================================
--- websites/production/tapestry/content/integrating-with-jpa.html (original)
+++ websites/production/tapestry/content/integrating-with-jpa.html Sun Apr 26 21:22:55 2020
@@ -83,11 +83,11 @@
</div><p>Tapestry provides a built-in integration with the Java Persistence API (JPA) through the <strong>Tapestry-jpa</strong> module. This module supersedes the 3rd-party <a class="external-link" href="http://www.tynamo.org/tapestry-jpa+guide/" rel="nofollow">Tynamo JPA module</a>.</p><p><strong>Contents</strong></p><p><style type="text/css">/*<![CDATA[*/
-div.rbtoc1523334080576 {padding: 0px;}
-div.rbtoc1523334080576 ul {list-style: disc;margin-left: 0px;}
-div.rbtoc1523334080576 li {margin-left: 0px;padding-left: 0px;}
+div.rbtoc1587936091316 {padding: 0px;}
+div.rbtoc1587936091316 ul {list-style: disc;margin-left: 0px;}
+div.rbtoc1587936091316 li {margin-left: 0px;padding-left: 0px;}
-/*]]>*/</style></p><div class="toc-macro rbtoc1523334080576">
+/*]]>*/</style></p><div class="toc-macro rbtoc1587936091316">
<ul class="toc-indentation"><li><a href="#IntegratingwithJPA-Downloading">Downloading</a>
<ul class="toc-indentation"><li><a href="#IntegratingwithJPA-SelectingaJPAImplementation">Selecting a JPA Implementation</a></li></ul>
</li><li><a href="#IntegratingwithJPA-ConfiguringJPA">Configuring JPA</a>
@@ -96,19 +96,19 @@ div.rbtoc1523334080576 li {margin-left:
<ul class="toc-indentation"><li><a href="#IntegratingwithJPA-InjectingtheEntityManagerintopageandcomponentclasses">Injecting the EntityManager into page and component classes</a></li><li><a href="#IntegratingwithJPA-InjectingEntityManagerintoservices">Injecting EntityManager into services</a></li></ul>
</li><li><a href="#IntegratingwithJPA-ValueEncoders">Value Encoders</a></li><li><a href="#IntegratingwithJPA-TransactionManagement">Transaction Management</a></li></ul>
</div><h1 id="IntegratingwithJPA-Downloading">Downloading</h1><p>The<strong> Tapestry-jpa</strong> module is not automatically included in Tapestry applications because of the additional dependencies it requires. If you're using Maven, just add the <code>tapestry-jpa</code> dependency to your application's pom.xml file, something like this:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>pom.xml (partial)</b></div><div class="codeContent panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"><dependency>
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: xml; gutter: false; theme: Default" data-theme="Default"><dependency>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-jpa</artifactId>
<version>${tapestry-version}</version>
</dependency></pre>
</div></div><p>If you aren't using Maven (or Gradle, Ivy, etc), you'll have to download the jar and its dependencies yourself.</p><h2 id="IntegratingwithJPA-SelectingaJPAImplementation">Selecting a JPA Implementation</h2><p>The Tapestry-jpa module includes a dependency on a JPA specification (API) from Geronimo but not an implementation. You'll have to chose a JPA implementation, such as EclipseLink or Hibernate. The Tapestry-jpa module assumes you'll use Eclipselink. You just have to add the EclipseLink dependency:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>pom.xml (partial) for EclipseLink</b></div><div class="codeContent panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"><dependency>
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: xml; gutter: false; theme: Default" data-theme="Default"><dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>${eclipselink-version}</version>
</dependency></pre>
</div></div><p>Or, if you'd rather use Hibernate as your JPA implementation, you'll want to exclude either the Gernonimo or Hibernate JPA specification JAR:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>pom.xml (partial) for Hibernate</b></div><div class="codeContent panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"><dependency>
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: xml; gutter: false; theme: Default" data-theme="Default"><dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate-version}</version>
@@ -121,7 +121,7 @@ div.rbtoc1523334080576 li {margin-left:
</exclusions>
</dependency></pre>
</div></div><h1 id="IntegratingwithJPA-ConfiguringJPA">Configuring JPA</h1><p>The <strong>persistence.xml</strong> file is the standard configuration file in JPA used to define the persistence units. Tapestry reads this file to create the <a class="external-link" href="http://download.oracle.com/javaee/6/api/javax/persistence/EntityManagerFactory.html" rel="nofollow">EntityManagerFactory</a>. The following example demonstrates a persistence.xml file.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>persistence.xml</b></div><div class="codeContent panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"><?xml version="1.0" encoding="UTF-8"?>
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: xml; gutter: false; theme: Default" data-theme="Default"><?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="DemoUnit" transaction-type="RESOURCE_LOCAL">
<properties>
@@ -135,7 +135,7 @@ div.rbtoc1523334080576 li {margin-left:
</persistence></pre>
</div></div><p>By default, the persistence descriptor is named <em>persistence.xml</em> and is expected to be located on the classpath in the <em>META-INF</em> directory. If you want to place the <em>persistence.xml</em> file in another directory or name it differently, you can make a contribution to the <em>SymbolProvider</em> service, as shown in the following example. This is a quite useful feature if you want to use a different persistence descriptor for tests.</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 AppModule {
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java; gutter: false; theme: Default" data-theme="Default">public class AppModule {
@Contribute(SymbolProvider.class)
@FactoryDefaults
@@ -145,7 +145,7 @@ div.rbtoc1523334080576 li {margin-left:
}</pre>
</div></div><h2 id="IntegratingwithJPA-XML-lessJPAconfiguration">XML-less JPA configuration</h2><p>With Tapestry, configuring JPA can be much simpler than described by the JPA specification. Tapestry allows you to configure the <a class="external-link" href="http://download.oracle.com/javaee/6/api/javax/persistence/EntityManagerFactory.html" rel="nofollow">EntityManagerFactory</a> programmatically, without writing any XML. For example, imagine that you want to use JDBC connections managed by the container and provided through JNDI. The resulting persistence descriptor might look like this:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>persistence.xml</b></div><div class="codeContent panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"><?xml version="1.0" encoding="UTF-8"?>
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: xml; gutter: false; theme: Default" data-theme="Default"><?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
version="2.0">
<persistence-unit name="JTAUnit" transaction-type="RESOURCE_LOCAL">
@@ -157,7 +157,7 @@ div.rbtoc1523334080576 li {margin-left:
</persistence-unit>
</persistence></pre>
</div></div><p>Now let's see how to provide the same configuration <em>without</em> XML. The following demonstrates an equivalent JPA configuration.</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 class AppModule {
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java; gutter: false; theme: Default" data-theme="Default">public class AppModule {
@Contribute(EntityManagerSource.class)
public static void configurePersistenceUnitInfos(MappedConfiguration<String,PersistenceUnitConfigurer> cfg) {
@@ -173,7 +173,7 @@ div.rbtoc1523334080576 li {margin-left:
}
}</pre>
</div></div><p>In the example above you can see a contribution to the <em>EntityManagerSource</em> service. This service is responsible for creating the <a class="external-link" href="http://download.oracle.com/javaee/6/api/javax/persistence/EntityManagerFactory.html" rel="nofollow">EntityManagerFactory</a> to be used to create <a class="external-link" href="http://download.oracle.com/javaee/6/api/javax/persistence/EntityManager.html" rel="nofollow">EntityManager</a>. When the service is initialized, it parses the <em>persistence.xml</em> file, if available. For any persistence unit defined in the XML descriptor a <em>TapestryPersistenceUnitInfo</em> object is created. The <em>TapestryPersistenceUnitInfo</em> interface is a mutable extension of the <a class="external-link" href="http://download.oracle.com/javaee/6/api/javax/persistence/spi/PersistenceUnitInfo.html" rel="nofollow">PersistenceUnitInfo</a> interface (defined in the JPA specification) that allows you to configure a p
ersistence unit programmatically.</p><p>After parsing the persistence descriptor, the EntityManagerSource service applies its configuration to create further persistence units and/or update the existing ones. The service’s configuration is a map in which persistence unit names are associated with <em>PersistenceUnitConfigurer</em> instances. A PersistenceUnitConfigurer is used to configure a persistence unit programmatically that has been associated with it. In the example above you can see a contribution providing a PersistenceUnitConfigurer for the unit named <em>JTAUnit</em>.</p><div class="confluence-information-macro confluence-information-macro-information"><span class="aui-icon aui-icon-small aui-iconfont-info confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>Note that the TapestryPersistenceUnitInfo instance passed to the PersistenceUnitConfigurer is either empty or my contain the persistence unit metadata read from the persist
ence.xml file. What happens if you contribute a PersistenceUnitConfigurer for a persistence unit that has not been defined in the persistence.xml file? In this case Tapestry assumes that you want to configure the persistence unit programmatically and just creates a fresh <em>TapestryPersistenceUnitInfo</em> object and passes it to the <em>PersistenceUnitConfigurer</em>.</p></div></div><h2 id="IntegratingwithJPA-Automaticallyaddingmanagedclasses">Automatically adding managed classes</h2><p>If only a single persistence unit is defined, Tapestry scans the <em>application-root-package.entities</em> package. The classes in that package are automatically added as managed classes to the defined persistence unit.</p><p>If you have additional packages containing entities, you may contribute them to the <em>JpaEntityPackageManager</em> service configuration.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>A
ppModule.java (partial)</b></div><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">public class AppModule {
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java; gutter: false; theme: Default" data-theme="Default">public class AppModule {
@Contribute(JpaEntityPackageManager.class)
public static void providePackages(Configuration<String> configuration) {
@@ -183,7 +183,7 @@ div.rbtoc1523334080576 li {margin-left:
}
}</pre>
</div></div><p>As you can see, you may add as many packages as you wish.</p><h2 id="IntegratingwithJPA-ConfigurationSettings">Configuration Settings</h2><p>Several aspects of Tapestry-jpa can be customized in your application module (usually AppModule.java), just like other Tapestry <a href="configuration.html">configuration symbols</a>.</p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh">Symbol</th><th colspan="1" rowspan="1" class="confluenceTh">Default</th><th colspan="1" rowspan="1" class="confluenceTh">Description</th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">JpaSymbols.PROVIDE_ENTITY_VALUE_ENCODERS</td><td colspan="1" rowspan="1" class="confluenceTd">true</td><td colspan="1" rowspan="1" class="confluenceTd">Whether entity value encoders will be provided automatically. See <a href="integrating-with-jpa.html">Using Select with a List</a>.</td></tr><tr><td colspan="1" rowspan="1" class="confluence
Td">JpaSymbols.EARLY_START_UP</td><td colspan="1" rowspan="1" class="confluenceTd">true</td><td colspan="1" rowspan="1" class="confluenceTd"><span style="color: rgb(33,33,33);">Whether JPA will be started up at application launch, rather than lazily.</span></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">JpaSymbols.ENTITY_SESSION_STATE_PERSISTENCE_STRATEGY_ENABLED</td><td colspan="1" rowspan="1" class="confluenceTd">true</td><td colspan="1" rowspan="1" class="confluenceTd"><p>Whether the "entity" persistence strategy is used to store JPA entities as <code>Session State Objects</code>.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">JpaSymbols.PERSISTENCE_DESCRIPTOR</td><td colspan="1" rowspan="1" class="confluenceTd">/META-INF/persistence.xml</td><td colspan="1" rowspan="1" class="confluenceTd"><span style="color: rgb(33,33,33);">The location of the persistence configuration file, located on the classpath </span></td></tr></tbody></table></div><h
1 id="IntegratingwithJPA-InjectingtheEntityManager">Injecting the EntityManager</h1><p>The created entity managers can be injected into page, component and other services.</p><h2 id="IntegratingwithJPA-InjectingtheEntityManagerintopageandcomponentclasses">Injecting the EntityManager into page and component classes</h2><p>Depending on whether more than one persistence unit has been defined, the way to inject <a class="external-link" href="http://download.oracle.com/javaee/6/api/javax/persistence/EntityManager.html" rel="nofollow">EntityManager</a> varies slightly. Let’s start with a simple scenario, where only a single persistence unit is defined. In this case, an EntityManager can be injected using the @<a class="external-link" href="http://download.oracle.com/javaee/6/api/javax/persistence/PersistenceContext.html" rel="nofollow">PersistenceContext</a> annotation.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-
bottom-width: 1px;"><b>CreateAddress.java</b></div><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">public class CreateAddress {
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java; gutter: false; theme: Default" data-theme="Default">public class CreateAddress {
@PersistenceContext
private EntityManager entityManager;
@@ -197,7 +197,7 @@ div.rbtoc1523334080576 li {margin-left:
}
}</pre>
</div></div><p>Alternatively, you can use the @Inject annotation to get the EntityManager injected into a page or component, as shown in the following example.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>CreateAddress.java</b></div><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">public class CreateAddress {
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java; gutter: false; theme: Default" data-theme="Default">public class CreateAddress {
@Inject
private EntityManager entityManager;
@@ -211,7 +211,7 @@ div.rbtoc1523334080576 li {margin-left:
}
}</pre>
</div></div><p>However, if you have multiple instances of persistence-unit defined in the same application, you need to explicitly tell Tapestry which persistence unit you want to get injected. This is what the @PersistenceContext annotation’s <em>name</em> attribute is used for? The following example demonstrates how to inject the persistence unit named <em>DemoUnit</em>.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>CreateAddress.java</b></div><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">public class CreateAddress {
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java; gutter: false; theme: Default" data-theme="Default">public class CreateAddress {
@PersistenceContext(unitName = "DemoUnit")
private EntityManager entityManager;
@@ -226,14 +226,14 @@ div.rbtoc1523334080576 li {margin-left:
}
}</pre>
</div></div><h2 id="IntegratingwithJPA-InjectingEntityManagerintoservices">Injecting EntityManager into services</h2><p>While component injection occurs only on fields, the injection in the IoC layer may be triggered by a field or a constructor. The following example demonstrates field injection, when a single persistence unit is defined in the persistence descriptor.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>UserDaoImpl.java</b></div><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">public class UserDaoImpl implements UserDao {
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java; gutter: false; theme: Default" data-theme="Default">public class UserDaoImpl implements UserDao {
@Inject
private EntityManager entityManager;
...
}</pre>
</div></div><p>The constructor injection is demonstrated in the following example.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>UserDaoImpl</b></div><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">public class UserDaoImpl implements UserDao {
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java; gutter: false; theme: Default" data-theme="Default">public class UserDaoImpl implements UserDao {
private EntityManager entityManager;
@@ -244,7 +244,7 @@ div.rbtoc1523334080576 li {margin-left:
...
}</pre>
</div></div><p>If multiple persistence units are defined in the same application, you need to disambiguate the unit to inject. This is done with the <a class="external-link" href="http://download.oracle.com/javaee/6/api/javax/persistence/PersistenceContext.html" rel="nofollow">@PersistenceContext</a> annotation, as shown in the following example. Because @PersistenceContext must not be placed on constructor parameters, you can’t use constructor injection and must switch to field injection.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>UserDaoImpl</b></div><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">public class UserDaoImpl implements UserDao {
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java; gutter: false; theme: Default" data-theme="Default">public class UserDaoImpl implements UserDao {
@Inject
@PersistenceContext(unitName = "DemoUnit")
private EntityManager entityManager;
@@ -252,7 +252,7 @@ div.rbtoc1523334080576 li {margin-left:
...
}</pre>
</div></div><h1 id="IntegratingwithJPA-ValueEncoders">Value Encoders</h1><p>The Tapestry-jpa module automatically provides <em>value encoders</em> to make it easy to work with entities (especially lists of entities) in your Tapestry pages and components. This is modeled on the similar functionality from the Tapestry-hibernate-core module. See the <a href="hibernate-user-guide.html">Hibernate User Guide</a> for all the details.</p><h1 id="IntegratingwithJPA-TransactionManagement">Transaction Management</h1><p>As you may already know from the Hibernate integration library, Tapestry automatically manages transactions for you. The JPA integration library defines the @CommitAfter annotation, which acts as the correspondent annotation from the Hibernate integration library. Let’s explore the <em>UserDao </em>interface to see the annotation in action.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1p
x;"><b>UserDao.java</b></div><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">public interface UserDao {
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java; gutter: false; theme: Default" data-theme="Default">public interface UserDao {
@CommitAfter
@PersistenceContext(unitName = "DemoUnit")
@@ -265,7 +265,7 @@ div.rbtoc1523334080576 li {margin-left:
void delete(User... users);
}</pre>
</div></div><p>As you can see, the annotation may be placed on service method in order to mark that method as transactional. Any method marked with the @CommitAfter annotation will have a transaction started before, and committed after, it is called. Runtime exceptions thrown by by a transactional method will abort the transaction. Checked exceptions are ignored and the transaction will be committed anyway.</p><div class="confluence-information-macro confluence-information-macro-warning"><span class="aui-icon aui-icon-small aui-iconfont-error confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>Note that <a class="external-link" href="http://download.oracle.com/javaee/6/api/javax/persistence/EntityTransaction.html" rel="nofollow">EntityTransaction</a> interface does not support two phase commits. Committing transactions of multiple EntityManagers in the same request might result in data consistency issues. That’s why @CommitAfter annotat
ion must be accompanied by the @PersistenceContext annotation if multiple persistence unit are defined in an application. This way you can only commit the transaction of a single persistence unit. You should be very carefully, if you are committing multiple transactions manually in the same request.</p></div></div><p>After placing the @CommitAfter annotation on methods, you need to tell Tapestry to advise those methods. This is accomplished by adding the transaction advice, as shown in the following example.</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 class AppModule {
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java; gutter: false; theme: Default" data-theme="Default">public class AppModule {
@Match("*Dao")
public static void adviseTransactionally(
Modified: websites/production/tapestry/content/integrating-with-spring-framework.html
==============================================================================
--- websites/production/tapestry/content/integrating-with-spring-framework.html (original)
+++ websites/production/tapestry/content/integrating-with-spring-framework.html Sun Apr 26 21:22:55 2020
@@ -85,11 +85,13 @@
+
+
<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>
+ <span class="icon aui-icon content-type-page" title="Page">Page:</span> </div>
<div class="details">
<a href="integrating-with-spring-framework.html">Integrating with Spring Framework</a>
@@ -98,7 +100,7 @@
</div>
</li><li>
<div>
- <span class="icon aui-icon aui-icon-small aui-iconfont-page-default" title="Page">Page:</span> </div>
+ <span class="icon aui-icon content-type-page" title="Page">Page:</span> </div>
<div class="details">
<a href="security.html">Security</a>
@@ -110,40 +112,40 @@
<p>For integrating Spring Security into your application, see <a href="security.html">Security</a>.</p><p><strong>Contents</strong></p><p><style type="text/css">/*<![CDATA[*/
-div.rbtoc1523334008411 {padding: 0px;}
-div.rbtoc1523334008411 ul {list-style: disc;margin-left: 0px;}
-div.rbtoc1523334008411 li {margin-left: 0px;padding-left: 0px;}
+div.rbtoc1587935977507 {padding: 0px;}
+div.rbtoc1587935977507 ul {list-style: disc;margin-left: 0px;}
+div.rbtoc1587935977507 li {margin-left: 0px;padding-left: 0px;}
-/*]]>*/</style></p><div class="toc-macro rbtoc1523334008411">
+/*]]>*/</style></p><div class="toc-macro rbtoc1587935977507">
<ul class="toc-indentation"><li>Related Articles</li></ul>
<ul><li><a href="#IntegratingwithSpringFramework-SpringVersion">Spring Version</a></li><li><a href="#IntegratingwithSpringFramework-Usage">Usage</a>
<ul class="toc-indentation"><li><a href="#IntegratingwithSpringFramework-Requireddependency">Required dependency</a></li><li><a href="#IntegratingwithSpringFramework-Updateyourweb.xmlfile">Update your web.xml file</a></li><li><a href="#IntegratingwithSpringFramework-AccessingtheSpringApplicationContext">Accessing the Spring Application Context</a></li><li><a href="#IntegratingwithSpringFramework-Injectingbeans">Injecting beans</a></li><li><a href="#IntegratingwithSpringFramework-InjectingTapestryservicesinSpringbeans">Injecting Tapestry services in Spring beans</a></li></ul>
</li><li><a href="#IntegratingwithSpringFramework-ApplicationContextCustomizer">ApplicationContextCustomizer</a></li><li><a href="#IntegratingwithSpringFramework-5.0CompatibilityMode">5.0 Compatibility Mode</a></li><li><a href="#IntegratingwithSpringFramework-ChangesFrom5.0">Changes From 5.0</a></li><li><a href="#IntegratingwithSpringFramework-Limitations">Limitations</a></li></ul>
</div><h2 id="IntegratingwithSpringFramework-SpringVersion">Spring Version</h2><p>This module is compiled and tested against Spring Framework 2.5.6. It should be reasonable to override the dependency to earlier versions of Spring, though the code makes use of some APIs that were added to Spring to support JDK 1.5 annotations.</p><h2 id="IntegratingwithSpringFramework-Usage">Usage</h2><p>The integration is designed to be a very thin layer on top of Spring's normal configuration for a web application.</p><p>Detailed instructions are available in the <a class="external-link" href="http://static.springframework.org/spring/docs/2.5.x/reference/beans.html#context-create" rel="nofollow">Spring documentation</a>. Please omit the part about creating a ContextLoaderListener: this is now done automatically by Tapestry.</p><h3 id="IntegratingwithSpringFramework-Requireddependency">Required dependency</h3><p>To integrate Spring with Tapestry, you should add the below dependency in your classpat
h. The following exemple is for Maven users.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"> <dependency>
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: xml; gutter: false; theme: Default" data-theme="Default"> <dependency>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-spring</artifactId>
<version>[your-tapestry-version]</version>
</dependency>
</pre>
</div></div><h3 id="IntegratingwithSpringFramework-Updateyourweb.xmlfile">Update your web.xml file</h3><p>The short form is that you must make two small changes to your application's web.xml.</p><p>First, a special filter is used in replace of the standard TapestryFilter:</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;"> <filter>
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java; gutter: false; theme: Default" data-theme="Default"> <filter>
<filter-name>app</filter-name>
<!-- Special filter that adds in a T5 IoC module derived from the Spring WebApplicationContext. -->
<filter-class>org.apache.tapestry5.spring.TapestrySpringFilter</filter-class>
</filter></pre>
</div></div><p>Secondly, you may add the normal Spring configuration, consisting of an optional <context-param> identifying which Spring bean configuration file(s) to load:</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;"><context-param>
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java; gutter: false; theme: Default" data-theme="Default"><context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/daoContext.xml /WEB-INF/applicationContext.xml</param-value>
</context-param>
</pre>
</div></div><p>The <context-param> lists the Spring bean configuration file. It is optional and defaults to just /WEB-INF/applicationContext.xml if omitted.</p><h3 id="IntegratingwithSpringFramework-AccessingtheSpringApplicationContext">Accessing the Spring Application Context</h3><p>By integrating Spring in Tapestry, you get full access on Spring ApplicationContext as if you were accessing to any Tapestry service. Simply @<a class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/annotations/Inject.html">Inject</a> into your pages and components.</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;"> @Inject
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java; gutter: false; theme: Default" data-theme="Default"> @Inject
private ApplicationContext springContext;
</pre>
</div></div><h3 id="IntegratingwithSpringFramework-Injectingbeans">Injecting beans</h3><p>Inside your component classes, you may use the @<a class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/annotations/Inject.html">Inject</a> annotation. Typically, just adding @<a class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/annotations/Inject.html">Inject</a> to the field type is sufficient to identify the Spring bean to inject:</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;"> @Inject
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java; gutter: false; theme: Default" data-theme="Default"> @Inject
private UserDAO userDAO;</pre>
</div></div><p>Searching for Spring beans is threaded into the <a href="injection-in-detail.html">MasterObjectProvider service</a>. The Spring context becomes one more place that Tapestry searches when determining the injection for a injected field or method parameter.</p><h3 id="IntegratingwithSpringFramework-InjectingTapestryservicesinSpringbeans">Injecting Tapestry services in Spring beans</h3>
Modified: websites/production/tapestry/content/integration-testing.html
==============================================================================
--- websites/production/tapestry/content/integration-testing.html (original)
+++ websites/production/tapestry/content/integration-testing.html Sun Apr 26 21:22:55 2020
@@ -85,11 +85,13 @@
+
+
<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>
+ <span class="icon aui-icon content-type-page" title="Page">Page:</span> </div>
<div class="details">
<a href="integration-testing.html">Integration Testing</a>
@@ -98,7 +100,7 @@
</div>
</li><li>
<div>
- <span class="icon aui-icon aui-icon-small aui-iconfont-page-default" title="Page">Page:</span> </div>
+ <span class="icon aui-icon content-type-page" title="Page">Page:</span> </div>
<div class="details">
<a href="unit-testing-pages-or-components.html">Unit testing pages or components</a>
@@ -110,7 +112,7 @@
<p>The Tapestry Test Utilities is a small library to make it easier to build integration test suites around <a class="external-link" href="http://www.seleniumhq.org" rel="nofollow">Selenium</a> version 2.14.0.</p><p>The strategy is to start, in-process, a Selenium Server (which, in turn, starts and manages a web browser), a Jetty instance (for the web browser to talk to), and a Selenium client (which talks to the server).</p><p>The client is able to request URLs, fill in form data, click links, and make assertions about output and behavior.</p><h1 id="IntegrationTesting-Usage">Usage</h1><p>The core part of this library is a base class for you to extend your tests classes : <a class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/test/SeleniumTestCase.html">SeleniumTestCase</a>.</p><p>This class is responsible for starting an instance of Jetty to server your web application, as well as a copy of Selenium Server. It also implements the <a class
="external-link" href="http://release.openqa.org/selenium-remote-control/0.9.0/doc/java/" rel="nofollow">Selenium</a> interface.</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>Before Tapestry 5.2, your class should extend AbstractIntegrationTestSuite</p></div></div><p>Here's an example from one of the Tapestry modules:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Your Integration Test Class : SinglePersistenceUnitIntegrationTest.java</b></div><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">package org.apache.tapestry5.jpa.integration.app2;
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java; gutter: false; theme: Default" data-theme="Default">package org.apache.tapestry5.jpa.integration.app2;
import org.apache.tapestry5.test.SeleniumTestCase;
import org.testng.annotations.Test;
@@ -130,7 +132,7 @@ public class SinglePersistenceUnitIntegr
}
</pre>
</div></div><p>With the SeleniumTestCase class, you can use basic Selenium methods (such as open() and type()) and methods added by the SeleniumTestCase base class (clickAndWait() and assertFieldValue()).</p><p>In addition, the SeleniumTestCase base class extends the normal exception reporting provided by Selenium; when a failure occurs inside Selenium server, a more detailed message, including the current page's HTML source, is reported to System.err.</p><h1 id="IntegrationTesting-Configuration">Configuration</h1><p>All the configuration of your Integration Tests should be in your testng.xml file. Tapestry provides some parameters, in order to have the right environment for your tests.</p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Parameter</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Default Value</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Value</p></th></tr><tr><td colspan="
1" rowspan="1" class="confluenceTd"><p>tapestry.web-app-folder</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>src/main/webapp</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The path to a web app</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>tapestry.servlet-container</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>jetty7</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>the server container to use for the integration tests (jetty7 or tomcat6)</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>tapestry.context-path</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p> </p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The context path</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>tapestry.port</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>9090</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The web server port</p></td></tr><tr
><td colspan="1" rowspan="1" class="confluenceTd"><p>tapestry.ssl-port</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>8443</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The web server ssl port</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p>tapestry.browser-start-command</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>*firefox</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The browser command to pass to Selenium</p></td></tr></tbody></table></div><p>Here's an example :</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>testng.xml</b></div><div class="codeContent panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"><suite name="Selenium Tests Suite" annotations="1.5">
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: xml; gutter: false; theme: Default" data-theme="Default"><suite name="Selenium Tests Suite" annotations="1.5">
<test name="Integration Tests" enabled="true">
<parameter name="tapestry.browser-start-command" value="*googlechrome" />
<parameter name="tapestry.port" value="9091" />
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 Sun Apr 26 21:22:55 2020
@@ -78,11 +78,11 @@
<div id="content">
<div id="ConfluenceContent"><h1 id="Integrationwithexistingapplications-Integrationwithexistingapplications">Integration with existing applications</h1><h2 id="Integrationwithexistingapplications-Contents">Contents</h2><p><style type="text/css">/*<![CDATA[*/
-div.rbtoc1587536391329 {padding: 0px;}
-div.rbtoc1587536391329 ul {list-style: disc;margin-left: 0px;}
-div.rbtoc1587536391329 li {margin-left: 0px;padding-left: 0px;}
+div.rbtoc1587936110545 {padding: 0px;}
+div.rbtoc1587936110545 ul {list-style: disc;margin-left: 0px;}
+div.rbtoc1587936110545 li {margin-left: 0px;padding-left: 0px;}
-/*]]>*/</style></p><div class="toc-macro rbtoc1587536391329">
+/*]]>*/</style></p><div class="toc-macro rbtoc1587936110545">
<ul class="toc-indentation"><li><a href="#Integrationwithexistingapplications-HowdoImakeaformonaJSPsubmitintoTapestry?">How do I make a form on a JSP submit into Tapestry?</a></li><li><a href="#Integrationwithexistingapplications-HowdoIshareinformationbetweenaJSPapplicationandtheTapestryapplication?">How do I share information between a JSP application and the Tapestry application?</a></li><li><a href="#Integrationwithexistingapplications-HowdoIputtheTapestryapplicationinsideafolder,toavoidconflicts?">How do I put the Tapestry application inside a folder, to avoid conflicts?</a></li></ul>
</div><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><h2 id="Integrationwithexistingapplications-HowdoImakeaformonaJSPsubmitintoTapestry?">How do I make a form on a JSP submit into Tapestry?</h2><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>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>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="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>LoginForm.tml</b></div><div class="codeContent panelContent pdl">
<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: xml; gutter: false; theme: Default" data-theme="Default"><form method="post" action="/loginform">
Modified: websites/production/tapestry/content/introduction.html
==============================================================================
--- websites/production/tapestry/content/introduction.html (original)
+++ websites/production/tapestry/content/introduction.html Sun Apr 26 21:22:55 2020
@@ -76,20 +76,22 @@
+
+
<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>
+ <span class="icon aui-icon content-type-page" title="Page">Page:</span> </div>
<div class="details">
- <a href="tapestry-for-jsf-users.html">Tapestry for JSF Users</a>
+ <a href="getting-started.html">Getting Started</a>
</div>
</li><li>
<div>
- <span class="icon aui-icon aui-icon-small aui-iconfont-page-default" title="Page">Page:</span> </div>
+ <span class="icon aui-icon content-type-page" title="Page">Page:</span> </div>
<div class="details">
<a href="tapestry-tutorial.html">Tapestry Tutorial</a>
@@ -98,28 +100,28 @@
</div>
</li><li>
<div>
- <span class="icon aui-icon aui-icon-small aui-iconfont-page-default" title="Page">Page:</span> </div>
+ <span class="icon aui-icon content-type-page" title="Page">Page:</span> </div>
<div class="details">
- <a href="principles.html">Principles</a>
+ <a href="introduction.html">Introduction</a>
</div>
</li><li>
<div>
- <span class="icon aui-icon aui-icon-small aui-iconfont-page-default" title="Page">Page:</span> </div>
+ <span class="icon aui-icon content-type-page" title="Page">Page:</span> </div>
<div class="details">
- <a href="getting-started.html">Getting Started</a>
+ <a href="tapestry-for-jsf-users.html">Tapestry for JSF Users</a>
</div>
</li><li>
<div>
- <span class="icon aui-icon aui-icon-small aui-iconfont-page-default" title="Page">Page:</span> </div>
+ <span class="icon aui-icon content-type-page" title="Page">Page:</span> </div>
<div class="details">
- <a href="introduction.html">Introduction</a>
+ <a href="principles.html">Principles</a>
</div>
Modified: websites/production/tapestry/content/ioc.html
==============================================================================
--- websites/production/tapestry/content/ioc.html (original)
+++ websites/production/tapestry/content/ioc.html Sun Apr 26 21:22:55 2020
@@ -76,38 +76,40 @@
+
+
<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>
+ <span class="icon aui-icon content-type-page" title="Page">Page:</span> </div>
<div class="details">
- <a href="ioc.html">IOC</a>
+ <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>
+ <span class="icon aui-icon content-type-page" title="Page">Page:</span> </div>
<div class="details">
- <a href="ioc-cookbook.html">IoC cookbook</a>
+ <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>
+ <span class="icon aui-icon content-type-page" title="Page">Page:</span> </div>
<div class="details">
- <a href="tapestry-ioc-overview.html">Tapestry IoC Overview</a>
+ <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>
+ <span class="icon aui-icon content-type-page" title="Page">Page:</span> </div>
<div class="details">
<a href="tapestry-inversion-of-control-faq.html">Tapestry Inversion of Control FAQ</a>
Modified: websites/production/tapestry/content/javascript-faq.html
==============================================================================
--- websites/production/tapestry/content/javascript-faq.html (original)
+++ websites/production/tapestry/content/javascript-faq.html Sun Apr 26 21:22:55 2020
@@ -78,11 +78,11 @@
<div id="content">
<div id="ConfluenceContent"><h1 id="JavaScriptFAQ-JavaScript">JavaScript</h1><p>Main articles: <a href="client-side-javascript.html">Client-Side JavaScript</a>, <a href="legacy-javascript.html">Legacy JavaScript</a></p><h2 id="JavaScriptFAQ-Contents">Contents</h2><p><style type="text/css">/*<![CDATA[*/
-div.rbtoc1587536402299 {padding: 0px;}
-div.rbtoc1587536402299 ul {list-style: disc;margin-left: 0px;}
-div.rbtoc1587536402299 li {margin-left: 0px;padding-left: 0px;}
+div.rbtoc1587936109242 {padding: 0px;}
+div.rbtoc1587936109242 ul {list-style: disc;margin-left: 0px;}
+div.rbtoc1587936109242 li {margin-left: 0px;padding-left: 0px;}
-/*]]>*/</style></p><div class="toc-macro rbtoc1587536402299">
+/*]]>*/</style></p><div class="toc-macro rbtoc1587936109242">
<ul class="toc-indentation"><li><a href="#JavaScriptFAQ-WhydoIgeta"Tapestryisundefined"erroronformsubmit?(5.3andearlier)">Why do I get a "Tapestry is undefined" error on form submit? (5.3 and earlier)</a></li><li><a href="#JavaScriptFAQ-What'sthedifferencebetweentheT5objectandtheTapestryobjectinthebrowser?(5.3andearlier)">What's the difference between the T5 object and the Tapestry object in the browser? (5.3 and earlier)</a></li></ul>
</div><h2 id="JavaScriptFAQ-WhydoIgeta"Tapestryisundefined"erroronformsubmit?(5.3andearlier)">Why do I get a "Tapestry is undefined" error on form submit? (5.3 and earlier)</h2><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 href="configuration.html">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 browsers 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="confluen
ce-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 all the JavaScript files unpacked.</li></ul><h2 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)</h2><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>
Modified: websites/production/tapestry/content/javascript-rewrite-in-54.html
==============================================================================
--- websites/production/tapestry/content/javascript-rewrite-in-54.html (original)
+++ websites/production/tapestry/content/javascript-rewrite-in-54.html Sun Apr 26 21:22:55 2020
@@ -68,11 +68,11 @@
<div id="content">
<div id="ConfluenceContent"><div class="confluence-information-macro confluence-information-macro-information"><span class="aui-icon aui-icon-small aui-iconfont-info confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>This is a historical document in which Tapestry's Howard Lewis Ship describes the motivations and plan for significantly changing Tapestry's client-side functionality starting in Tapestry 5.4. This plan closely matches the actual results delivered in Tapestry 5.4, but this document is mostly kept for historical reference.</p></div></div><h2 id="JavaScriptRewritein5.4-Contents">Contents</h2><p><style type="text/css">/*<![CDATA[*/
-div.rbtoc1523334036754 {padding: 0px;}
-div.rbtoc1523334036754 ul {list-style: disc;margin-left: 0px;}
-div.rbtoc1523334036754 li {margin-left: 0px;padding-left: 0px;}
+div.rbtoc1587936024196 {padding: 0px;}
+div.rbtoc1587936024196 ul {list-style: disc;margin-left: 0px;}
+div.rbtoc1587936024196 li {margin-left: 0px;padding-left: 0px;}
-/*]]>*/</style></p><div class="toc-macro rbtoc1523334036754">
+/*]]>*/</style></p><div class="toc-macro rbtoc1587936024196">
<ul class="toc-indentation"><li><a href="#JavaScriptRewritein5.4-TapestryandJavaScript">Tapestry and JavaScript</a></li><li><a href="#JavaScriptRewritein5.4-TapestryJavaScriptLimitations(through5.3)">Tapestry JavaScript Limitations (through 5.3)</a>
<ul class="toc-indentation"><li><a href="#JavaScriptRewritein5.4-DependenceonPrototype/Scriptaculous">Dependence on Prototype/Scriptaculous</a></li><li><a href="#JavaScriptRewritein5.4-LackofDocumentation">Lack of Documentation</a></li><li><a href="#JavaScriptRewritein5.4-LackofModuleStructure">Lack of Module Structure</a></li><li><a href="#JavaScriptRewritein5.4-ComplexInitialization">Complex Initialization</a></li></ul>
</li><li><a href="#JavaScriptRewritein5.4-JavaScriptImprovementsfor5.4">JavaScript Improvements for 5.4</a>
Modified: websites/production/tapestry/content/layout-component.html
==============================================================================
--- websites/production/tapestry/content/layout-component.html (original)
+++ websites/production/tapestry/content/layout-component.html Sun Apr 26 21:22:55 2020
@@ -85,11 +85,13 @@
+
+
<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>
+ <span class="icon aui-icon content-type-page" title="Page">Page:</span> </div>
<div class="details">
<a href="component-parameters.html">Component Parameters</a>
@@ -98,25 +100,25 @@
</div>
</li><li>
<div>
- <span class="icon aui-icon aui-icon-small aui-iconfont-page-default" title="Page">Page:</span> </div>
+ <span class="icon aui-icon content-type-page" title="Page">Page:</span> </div>
<div class="details">
- <a href="templating-and-markup-faq.html">Templating and Markup FAQ</a>
+ <a href="component-classes.html">Component Classes</a>
</div>
</li><li>
<div>
- <span class="icon aui-icon aui-icon-small aui-iconfont-page-default" title="Page">Page:</span> </div>
+ <span class="icon aui-icon content-type-page" title="Page">Page:</span> </div>
<div class="details">
- <a href="component-classes.html">Component Classes</a>
+ <a href="templating-and-markup-faq.html">Templating and Markup FAQ</a>
</div>
</li><li>
<div>
- <span class="icon aui-icon aui-icon-small aui-iconfont-page-default" title="Page">Page:</span> </div>
+ <span class="icon aui-icon content-type-page" title="Page">Page:</span> </div>
<div class="details">
<a href="page-and-component-classes-faq.html">Page And Component Classes FAQ</a>
@@ -125,7 +127,7 @@
</div>
</li><li>
<div>
- <span class="icon aui-icon aui-icon-small aui-iconfont-page-default" title="Page">Page:</span> </div>
+ <span class="icon aui-icon content-type-page" title="Page">Page:</span> </div>
<div class="details">
<a href="component-templates.html">Component Templates</a>
@@ -134,7 +136,7 @@
</div>
</li><li>
<div>
- <span class="icon aui-icon aui-icon-small aui-iconfont-page-default" title="Page">Page:</span> </div>
+ <span class="icon aui-icon content-type-page" title="Page">Page:</span> </div>
<div class="details">
<a href="component-cheat-sheet.html">Component Cheat Sheet</a>
@@ -146,7 +148,7 @@
<p>You'll see frequent reference to a <strong>Layout Component</strong> in Tapestry documentation, but you won't find such a component in the <a href="component-reference.html">component reference</a>. The Layout component is a component <em>that you create</em> to provide common elements across all of your pages.</p><p>In traditional servlet development, you may be familiar with the use of a JSP include to include a banner across the top of your page and a copyright message across the bottom. In Tapestry, you <em>could</em> implement those recurring page elements as components (a banner component, a copyright component, etc.) and then add those components to every page.</p><p>But there's an even better way. Just create a layout component that provides the overall structure and recurring content for your pages:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Layout.tml (a template for a Layout co
mponent)</b></div><div class="codeContent panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"><html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_4.xsd">
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: xml; gutter: false; theme: Default" data-theme="Default"><html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_4.xsd">
<head>
<title>My Nifty Web Application</title>
</head>
@@ -164,7 +166,7 @@
</html>
</pre>
</div></div><p>In a real-world example, the two <div> elements above might contain the typical recurring content you'll see across the pages of a web application: banners, menus, login forms and so forth. Often these layout components get very complex ... in fact, in many applications the Layout component can grow to be as complex as any other component.</p><h2 id="LayoutComponent-UsingtheLayoutinaPage">Using the Layout in a Page</h2><p>To use your layout component, just have each page in your application <em>wrap itself</em> in the layout, like this:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Welcome.tml (the template for a page)</b></div><div class="codeContent panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"><html t:type="layout" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_4.xsd">
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: xml; gutter: false; theme: Default" data-theme="Default"><html t:type="layout" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_4.xsd">
<h1>Welcome to the Nifty Web Application!</h1>
@@ -174,13 +176,13 @@
</html>
</pre>
</div></div><p>Note the "t:type="layout" part. That says, in effect, "wrap the layout component around my <em>content</em>".</p><p>The magic is in the <t:body/> element of the layout template; this will be replaced by each page's <em>content</em>, whatever that is.</p><div class="confluence-information-macro confluence-information-macro-information"><span class="aui-icon aui-icon-small aui-iconfont-info confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>Remember that if your layout component includes a link to a resource such as an image or a stylesheet, you must use an <em>absolute</em> URL. The same component will be used for pages in many different folders, or with many different activation contexts, so relative URLs won't work. The best approach is to use the <a href="assets.html">context binding prefix</a>.</p></div></div><p>To keep our Welcome.tml page template relatively preview-able, we are using an <html> element and the
t:type attribute to specify that it is a component. At render time, the page's <html> tag will be removed, and replaced with the content from the Layout.tml template (which conveniently starts with an <html> element). The <t:body> element in Layout.tml will be replaced with the page-specific content here: the <h1> and <p> tags.</p><p>Any page in the application that follows this pattern, using the Layout component, will have the same look and feel.</p><p>Layout is a regular component like other, with an ordinary component template. Like all component templates, it will be stored on the classpath (typically under src/main/resources).</p><p>Components must always have a Java class. But in this trivial example, the Layout component doesn't need any logic:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Layout.java</b></div><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">@Import(stylesheet="context:css/site.css")
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java; gutter: false; theme: Default" data-theme="Default">@Import(stylesheet="context:css/site.css")
public class Layout
{
}
</pre>
</div></div><p>We use the @<a class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/annotations/Import.html">Import</a> annotation (in 5.2 or later), as opposed to directly adding the <link> element to the template, for significant performance benefits <a href="assets.html">described elsewhere</a>. (For 5.0 and 5.1, use the deprecated @IncludeStyleSheet annotation instead.)</p><p>You may find that your application has more than one look and feel: perhaps user registration pages have one look, while administrative pages have another. This can be accomplished by having multiple layout components (using any names you choose) and using those different layout types for different pages.</p><h2 id="LayoutComponent-NestedLayouts">Nested Layouts</h2><p>Layouts are really just ordinary components, so they can be nested to any level needed. You can have, for example, a "CommonLayout" component that provides the peripheral elements for all your page
s, and then a more specialized "AdminLayout" component that provides the layout only for the administrative pages, and make the AdminLayout component wrap itself in the CommonLayout component. So then the administrative pages would start with <code><html t:type="adminLayout" ...></code> and the other pages (and the AdminLayout component itself) would start with <code><html t:type="commonLayout" ...></code>.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>AdminLayout.tml</b></div><div class="codeContent panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"><html t:type="commonLayout" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_4.xsd">
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: xml; gutter: false; theme: Default" data-theme="Default"><html t:type="commonLayout" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_4.xsd">
<h1>Administrative Functions</h1>
@@ -189,7 +191,7 @@ public class Layout
</html>
</pre>
</div></div><h2 id="LayoutComponent-Amoreadvancedexample">A more advanced example</h2><p>Here's an example of a Layout component with a few more features. It has a "title" parameter, so that every page can pass in its own title to be rendered in the <title> tag <em>and</em> in an <h1> tag at the top of the HTML. There is also a "style" parameter that allows each page to pass in a block of CSS rules to be rendered in the <head> section of the page (useful for those few CSS rules that can't be put into a static CSS file). Notice the HTML5-style DOCTYPE declaration at the top, the charset definition as UTF-8, and the addition of an "alerts" component.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Layout.tml (a template for a Layout component)</b></div><div class="codeContent panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"><!DOCTYPE html>
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: xml; gutter: false; theme: Default" data-theme="Default"><!DOCTYPE html>
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_4.xsd">
<head>
<meta charset="UTF-8" />
@@ -216,7 +218,7 @@ public class Layout
</html>
</pre>
</div></div><p>The <a class="external-link" href="http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/Alerts.html">Alerts</a> component above (Tapestry 5.3 and later) allows the application to present alert messages to the client in a consistent way. If you want alerts to always appear in the banner of your web site, it may make sense to put it in the layout component's template, as above.</p><p>The corresponding component class is still very simple, adding support for the "title" and "style" parameters:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Layout.java</b></div><div class="codeContent panelContent pdl">
-<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">@Import(stylesheet="context:css/site.css")
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java; gutter: false; theme: Default" data-theme="Default">@Import(stylesheet="context:css/site.css")
public class Layout
{
/** The page title, for the <title> element and the <h1> element. */
@@ -231,7 +233,7 @@ public class Layout
}
</pre>
</div></div><p>Here's how you might use the above layout component for a UserList page:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>UserList.tml</b></div><div class="codeContent panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"><html t:type="layout" title="List of Users"
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: xml; gutter: false; theme: Default" data-theme="Default"><html t:type="layout" title="List of Users"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_4.xsd"
xmlns:p="tapestry:parameter">
<p:style>
@@ -245,7 +247,7 @@ public class Layout
</html>
</pre>
</div></div><p>The <p:style> element (and its contents) are passed to the layout component as a <code>style</code> parameter (a block parameter, in this case, so you must have the <code>xmlns:p="tapestry:parameter"</code> namespace declared, as above).</p><p>The rendered HTML would look like the following (whitespace aside, and assuming UserList.java has a backgroundImage property whose value is the string "<span class="nolink">http://www.example.com/fuzzy.gif</span>"):</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>The rendered HTML</b></div><div class="codeContent panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;"><!DOCTYPE html>
+<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: xml; gutter: false; theme: Default" data-theme="Default"><!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />