[CONF] Apache Tapestry Component Classes

2010-11-28 Thread confluence







Component Classes
Page edited by Bob Harner


Comment:
Added intro paragraph about component templates


 Changes (1)
 



...
_For Tapestry 4 Users: Component classes in Tapestry 5 are much easier than in Tapestry 4. There are no base classes to extend from, the classes are concrete (not abstract), and theres no XML file. There is still a bit of configuration in the form of Java annotations, but those now go directly onto fields of your class, rather than on abstract getters and setters._  
In most cases, each component class will have a corresponding [component template|Component Templates].  However, it is also possible for a component class to emit all of its markup itself, without using a template.  
h2. Component Class Basics  
...

Full Content

Component Classes

Related Articles
	Page And Component Classes FAQ
	Component Cheat Sheet
	Component Templates



A Component class is the class associated with a page, component or mixin in your Tapestry web application. Classes for pages, components and component mixins are all created in an identical way. They are pure POJOs (Plain Old Java Objects), with annotations.  They are not abstract, nor do they extend from framework base classes.

For Tapestry 4 Users: Component classes in Tapestry 5 are much easier than in Tapestry 4. There are no base classes to extend from, the classes are concrete (not abstract), and there's no XML file. There is still a bit of configuration in the form of Java annotations, but those now go directly onto fields of your class, rather than on abstract getters and setters.

In most cases, each component class will have a corresponding component template.  However, it is also possible for a component class to emit all of its markup itself, without using a template.

Component Class Basics

Creating page and component classes in Tapestry 5 is a breeze. There are only a few constraints:


	The classes must be public.
	The classes must be in the correct package (see below).
	The class must have a standard public, no-arguments constructor.



Here's a very basic component:



package org.example.myapp.components;

import org.apache.tapestry5.MarkupWriter;
import org.apache.tapestry5.annotations.BeginRender;

public class HelloWorld
{
@BeginRender
void renderMessage(MarkupWriter writer)
{
writer.write("Bonjour from HelloWorld component.");
}
}



In this example, the component's only job is to write out a fixed message. The @BeginRender annotation is a type of component life cycle annotation, a method annotation that instructs Tapestry when and under what circumstances to invoke methods of your class.

These methods are not necessarily public; they can have any visibility you like (unlike in Tapestry 4).

Component Packages

Component classes must exist within an appropriate package (this is necessary for runtime code transformation and class reloading to operate).

These packages exist under the application's root package, as follows:


	For pages, place classes in root.pages. Page names are mapped to classes within this package.
	For components, place classes in root.components. Component types are mapped to classes within this package.
	For mixins, place classes in root.mixins. Mixin types are mapped to classes within this package.



In addition, it is common for an application to have base classes, often abstract base classes, that should not be directly referenced. These should not go in the pages, components or mixins packages, because they then look like valid pages, components or mixins. Instead, use the root.base package to store such base classes.

Sub-Folders / Sub-Packages

Classes do not have to go directly inside the package (pages, components, mixins, etc.). It is valid to create a sub-package to store some of the classes. The sub-package name becomes part of the page name or component type. Thus you might define a page component com.example.myapp.pages.admin.CreateUser and the logical page name (which often shows up inside URLs) will be admin/CreateUser.

Tapestry performs some simple optimizations of the logical page name (or component type, or mixin type). It checks to see if the package name is either a prefix or a suffix of the unqualified class name (case insensitively, of course) and removes the prefix or suffix if so. The net result is that a class name such as com.example.myapp.pages.user.EditUser will have a page name of user/Edit (not user/EditUser). The goal here is to provide shorter, more natural URLs.

Pages vs. Components

The distinction between pages and component is very, very small. The only real difference is the package name: root.pages.PageName for pages, and root.components.ComponentType for components. 

[CONF] Apache Tapestry Documentation

2010-11-28 Thread confluence







Documentation
Page edited by Christophe Cordenier


Comment:
Create a section on User Guides for hot topics


 Changes (2)
 



...
- [Frequently Asked Questions] - [TAPESTRY:Component Cheat Sheet] -- a quick reference to common annotations and method names 
- [User Guide] -- a collection of detailed references to the concepts behind Tapestry 
- [Cookbook] -- a collection of tips and tricks for commonly occuring patterns in Tapestry - [Deployment Notes] -- a guide to deploying Tapestry on common application servers 
...
** [Release Notes|Release Notes 5.2.4]  
h2. User Guides  We provide a collection of [detailed references|User Guide] to the concepts behind Tapestry and beyond.  - Go to the [main user guides page|User Guide] - Unit test your application with [Tapestry test utilities|Test] - [Integrate Spring|spring] into your Tapestry application - Use [Tapestry Hibernate integration|Hibernate - Core - Conf] to build your data access layer  
h2. Articles  
...

Full Content



Overview


	Introduction
	Getting Started
	Tutorial
	Frequently Asked Questions
	Component Cheat Sheet  a quick reference to common annotations and method names
	Cookbook  a collection of tips and tricks for commonly occuring patterns in Tapestry
	Deployment Notes  a guide to deploying Tapestry on common application servers
	Developer Information
	Refcard  a six page foldout guide to Tapestry 5.0



Tapestry 5 Reference and API


	Current stable release 5.1.0.5
	
		API (Javadoc)
		Component Reference
		Release Notes
	
	




	Previous stable release 5.0.18
	
		API (Javadoc)
		Component Reference
		Release Notes
	
	




	Current beta release 5.2.4
	
		API (Javadoc)
		Component Reference
		Release Notes
	
	



User Guides

We provide a collection of detailed references to the concepts behind Tapestry and beyond.


	Go to the main user guide's page
	Unit test your application with Tapestry test utilities
	Integrate Spring into your Tapestry application
	Use Tapestry Hibernate integration to build your data access layer



Articles

If you have any doubts, Tapestry 5 for Nonbelievers will demonstrate why you should choose Tapestry 5

More articles...

Blogs


	Tapestry Central is Howard Lewis Ship's blog. As the creator of Tapestry, he provides a lot of valuable information on Tapestry's latest features and future directions.




	Igor Drobiazko's blog contains a lot of fresh news on Tapestry development and will guide you through the most exciting parts of  Tapestry.  Igor is a Tapestry Committer and PMC member.



More blogs ...

Books

There are at least 8 published books on Tapestry, including two on Tapestry 5  and more on the way.

Presentations


	JavaServer Faces 2.0 vs. Tapestry 5: A Head-to-Head Comparison by Igor Drobiazko at Jazoon 2010




	Tapestry 5: Java power, Scripting Ease by Howard Lewis Ship at Devoxx 2009




	More presentations ...



Wikis


	Community's Wiki (Moin Moin) contains a lot of user-generated information on different concrete web application use cases.
	Documentation Source wiki (Confluence)  the wiki used as the content editor for the official Tapestry documentation





Change Notification Preferences

View Online
|
View Changes









[CONF] Apache Tapestry Spring

2010-11-28 Thread confluence







Spring
Page edited by Christophe Cordenier


Comment:
Review page structure


 Changes (22)
 



{toc:type=list|maxLevel=3}  
h1. Tapestry/Spring Integration  Provides integration between Tapestry and Spring, allowing beans defined by Spring to be injected into Tapestry IoC services, and into Tapestry components.  
h1. Changes From 5.0 
h2. Spring Version 
 
You may now use the @Inject or @InjectService annotations inside Spring beans; these will be resolved to Tapestry services or other objects available via the MasterObjectProvider. Please see the [detailed guide to Injection|Injection].  The dependency on Spring is no longer scope provider and has changed to 2.5.6.  *Spring Beans are no longer exposed as services, unless 5.0 compatibility mode is enabled.*  You no longer create a ContextLoaderListener.  These changes represent an unfortunate backwards compatibility issue. If necessary, you can still use tapestry-spring version 5.0.18 with the rest of Tapestry.  h1. Spring Version  
This module is compiled and tested against Spring 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.  
h12. Usage 
 The integration is designed to be a very thin layer on top of Springs normal configuration for a web application. 
...
Detailed instructions are available in the [Spring documentation|http://static.springframework.org/spring/docs/2.5.x/reference/beans.html#context-create]. Please omit the part about creating a ContextLoaderListener: this is now done automatically by Tapestry.  
h2. web.xml changes 
h3. Update your web.xml file 
 The short form is that you must make two small changes to your applications web.xml. 
...
  param-namecontextConfigLocation/param-name   param-value/WEB-INF/daoContext.xml /WEB-INF/applicationContext.xml/param-value 
/context-param{code} 
{code} 
 The context-param lists the Spring bean configuration file. It is optional and defaults to just /WEB-INF/applicationContext.xml if omitted.  
h2. Injecting beans 
h3. Accessing the Spring Application Context 
 
Inside your component classes, you may use the [Inject|http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/annotations/Inject.html] annotation. Typically, just the field type is sufficient to identify the Spring bean to inject: 
By integrating Spring in Tapestry, you get full access on Spring ApplicationContext as if you were accessing to any Tapestry service. Simply [Inject|http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/annotations/Inject.html] into your pages and components. 
 {code:java}   @Inject 
  private ApplicationContext springContext; {code}  h3. Injecting beans  Inside your component classes, you may use the [Inject|http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/annotations/Inject.html] annotation. Typically, just [Inject|http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/annotations/Inject.html] the field type is sufficient to identify the Spring bean to inject:  {code:java}   @Inject 
  private UserDAO userDAO;{code}  
...
 {since:since=5.2} 
h23. Injecting Tapestry services in Spring beans 
 If you have configured Spring to allow annotation based injection, then you will be able to inject Tapestry services into your Spring Beans.  
This feature is only available when Spring ApplicationContext is not configured and loaded externally. 
 Inside your Spring beans, you may use [Inject|http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/annotations/Inject.html] and  [Autowired|http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/beans/factory/annotation/Autowired.html] annotations. 
 
Inside your Spring beans, you may use [Inject|http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/annotations/Inject.html] and [Autowired|http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/beans/factory/annotation/Autowired.html] annotations.  
Simply add these two annotations on top the field you want to inject in your Spring bean.  
...
{code:java}   private final MyService myService; 
 
  @Autowired   public UserDAOImpl(@Inject MyService myService) 
...
{code}  
h23. Configuring Spring with Tapestry Symbols 
 

[CONF] Apache Tapestry Spring

2010-11-28 Thread confluence







Spring
Page edited by Christophe Cordenier


Comment:
Use 'We' as the community


 Changes (1)
 



...
h1. Integrate Spring into Tapestry  
Provides We provide an integration between Tapestry and Spring, allowing beans defined by Spring to be injected into Tapestry IoC services, and into Tapestry components. 
 h2. Spring Version 
...

Full Content



Integrate Spring into Tapestry

Spring Version
Usage

Update your web.xml file
Accessing the Spring Application Context
Injecting beans
Injecting Tapestry services in Spring beans
Configuring Spring with Tapestry Symbols

ApplicationContextCustomizer

5.0 Compatibility Mode
Changes From 5.0
Limitations


Integrate Spring into Tapestry

We provide an integration between Tapestry and Spring, allowing beans defined by Spring to be injected into Tapestry IoC services, and into Tapestry components.

Spring Version

This module is compiled and tested against Spring 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.

Usage

The integration is designed to be a very thin layer on top of Spring's normal configuration for a web application.

Detailed instructions are available in the Spring documentation. Please omit the part about creating a ContextLoaderListener: this is now done automatically by Tapestry.

Update your web.xml file

The short form is that you must make two small changes to your application's web.xml.

First, a special filter is used in replace of the standard TapestryFilter:



  filter
filter-nameapp/filter-name
!-- Special filter that adds in a T5 IoC module derived from the Spring WebApplicationContext. --
filter-classorg.apache.tapestry5.spring.TapestrySpringFilter/filter-class
  /filter


Secondly, you may add the normal Spring configuration, consisting of an optional context-param identifying which Spring bean configuration file(s) to load:



context-param
  param-namecontextConfigLocation/param-name
  param-value/WEB-INF/daoContext.xml /WEB-INF/applicationContext.xml/param-value
/context-param



The context-param lists the Spring bean configuration file. It is optional and defaults to just /WEB-INF/applicationContext.xml if omitted.

Accessing the Spring Application Context

By integrating Spring in Tapestry, you get full access on Spring ApplicationContext as if you were accessing to any Tapestry service. Simply Inject into your pages and components.



  @Inject
  private ApplicationContext springContext;



Injecting beans

Inside your component classes, you may use the Inject annotation. Typically, just Inject the field type is sufficient to identify the Spring bean to inject:



  @Inject
  private UserDAO userDAO;


Searching for Spring beans is threaded into the MasterObjectProvider service. The Spring context becomes one more place that Tapestry searches when determining the injection for a injected field or method parameter.



Added in 5.2

Injecting Tapestry services in Spring beans

If you have configured Spring to allow annotation based injection, then you will be able to inject Tapestry services into your Spring Beans.

This feature is only available when Spring ApplicationContext is not configured and loaded externally.

Inside your Spring beans, you may use Inject and Autowired annotations.

Simply add these two annotations on top the field you want to inject in your Spring bean.



  @Inject
  @Autowired
  private MyService myService;



or use @Inject on top of arguments in @Autowired bean constructor methods



  private final MyService myService;

  @Autowired
  public UserDAOImpl(@Inject MyService myService)
  {
this.myService = myService;
  }



Configuring Spring with Tapestry Symbols

This is accomplished by a BeanFactoryPostProcessors that resolves the values of 'placeholders' from symbol values. In the following example the value of the Bean's property 'productionMode' is the value of the Tapestry's  symbol tapestry.production-mode



  bean id="myBean" class="org.example.MyBean"
property name="productionMode" value="${tapestry.production-mode}"/
  /bean





ApplicationContextCustomizer

A new chain-of-command service, ApplicationContextCustomizer allows the application context, created by Tapestry, to be customized as it is created. You may contribute your own ApplicationContextCustomizer instances as needed.

5.0 Compatibility Mode

In some circumstances, it is desirable to configure the Spring ApplicationContext externally. The context config-param "tapestry.use-external-spring-context" can be configured to "true". Tapestry will then use an existing 

[CONF] Apache Tapestry Setting Up Your Environment

2010-11-28 Thread confluence







Setting Up Your Environment
Page edited by Howard M. Lewis Ship


 Changes (0)
 



...

Full Content

Chapter 1: Setting Up Your Environment

As much as we would like to dive into Tapestry right now, we must first talk about your development environment. The joy and the pain of Java development is the volume of choice available. There's just a bewildering number of JDKs, IDEs and other TLAs (Three Letter Acronyms) out there.

Let's talk about a stack of tools, all open source and freely available, that you'll need to setup. Likely you have some of these, or some version of these, already on your development machine.

JDK 1.5 or Newer

Tapestry 5 makes use of features of JDK 1.5. This includes Java Annotations, and a little bit of Java Generics.  JDK 1.6 works fine too.

Eclipse Helios (3.6.1 or Newer)

Since we're emphasizing a free and open source stack, we'll concentrate on the best free IDE.

Ok, sure, IntelliJ is now free as well. And NetBeans has gotten really nice. Feel free to adapt these instructions to those IDEs.

Eclipse comes in various flavors, and includes a reasonable XML editor built-in.  It can be downloaded from the eclipse.org web site.  We recommend the Eclipse IDE for Java Developers.

Jetty

Jetty is an open source servlet container created by Greg Wilkins of Webtide (which offers commercial support for Jetty). Jetty is high performance and designed for easy embedding in other software.

RunJettyRun Eclipse Plugin

RunJettyRun is a very simple Eclipse plugin that bundles a version of Jetty (Jetty 6 at this writing) so that you can create Eclipse launches that start Jetty to execute your web application.

You can install RunJettyRun using Eclipse's Install New Software... menu item; the update URL is http://run-jetty-run.googlecode.com/svn/trunk/updatesite.

This tutorial was written with RunJettyRun version 1.1.1.

Maven 2.2.1

Maven is a software build tool of rather epic ambitions. It has a very sophisticated plugin system that allows it to do virtually anything, though compiling Java code, building WAR and JAR files, and creating reports and web sites are its forte.

Perhaps the biggest advantage of Maven over, say, Ant, is that it can download project dependencies (such as the Tapestry JAR files, and the JAR files Tapestry itself depends on) automatically for you, from one of several central repositories.

Maven is not essential for using Tapestry, but is especially helpful when performing the initial setup of a Tapestry application.

Maven 2.2.1 is available from http://maven.apache.org/download.html.

Maven 3.0 is now available but we have not tested the tutorial against it.

There are plugins available for Eclipse, but we will not be using those here; instead, we'll use Maven to generate Eclipse control files for us.

Tapestry 5.2.4

You should not have to download this directly; as we'll see, Maven should take care of downloading Tapestry, and its dependencies, as needed.

Continue on to Chapter 2: Your First Tapestry Application



Change Notification Preferences

View Online
|
View Changes









[CONF] Apache Tapestry Setting Up Your Environment

2010-11-28 Thread confluence







Setting Up Your Environment
Page edited by Howard M. Lewis Ship


 Changes (3)
 



h1. Chapter 1: Setting Up Your Environment 
 
 h1. Setting Up Your Environment  
As much as we would like to dive into Tapestry right now, we must first talk about your development environment. The joy and the pain of Java development is the volume of choice available. Theres just a bewildering number of JDKs, IDEs and other TLAs (Three Letter Acronyms) out there.  
...
You should not have to download this directly; as well see, Maven should take care of downloading Tapestry, and its dependencies, as needed.  
[Continue on to Chapter 2: Your First Tapestry Application|TAPESTRY:First] 

Full Content



Setting Up Your Environment

As much as we would like to dive into Tapestry right now, we must first talk about your development environment. The joy and the pain of Java development is the volume of choice available. There's just a bewildering number of JDKs, IDEs and other TLAs (Three Letter Acronyms) out there.

Let's talk about a stack of tools, all open source and freely available, that you'll need to setup. Likely you have some of these, or some version of these, already on your development machine.

JDK 1.5 or Newer

Tapestry 5 makes use of features of JDK 1.5. This includes Java Annotations, and a little bit of Java Generics.  JDK 1.6 works fine too.

Eclipse Helios (3.6.1 or Newer)

Since we're emphasizing a free and open source stack, we'll concentrate on the best free IDE.

Ok, sure, IntelliJ is now free as well. And NetBeans has gotten really nice. Feel free to adapt these instructions to those IDEs.

Eclipse comes in various flavors, and includes a reasonable XML editor built-in.  It can be downloaded from the eclipse.org web site.  We recommend the Eclipse IDE for Java Developers.

Jetty

Jetty is an open source servlet container created by Greg Wilkins of Webtide (which offers commercial support for Jetty). Jetty is high performance and designed for easy embedding in other software.

RunJettyRun Eclipse Plugin

RunJettyRun is a very simple Eclipse plugin that bundles a version of Jetty (Jetty 6 at this writing) so that you can create Eclipse launches that start Jetty to execute your web application.

You can install RunJettyRun using Eclipse's Install New Software... menu item; the update URL is http://run-jetty-run.googlecode.com/svn/trunk/updatesite.

This tutorial was written with RunJettyRun version 1.1.1.

Maven 2.2.1

Maven is a software build tool of rather epic ambitions. It has a very sophisticated plugin system that allows it to do virtually anything, though compiling Java code, building WAR and JAR files, and creating reports and web sites are its forte.

Perhaps the biggest advantage of Maven over, say, Ant, is that it can download project dependencies (such as the Tapestry JAR files, and the JAR files Tapestry itself depends on) automatically for you, from one of several central repositories.

Maven is not essential for using Tapestry, but is especially helpful when performing the initial setup of a Tapestry application.

Maven 2.2.1 is available from http://maven.apache.org/download.html.

Maven 3.0 is now available but we have not tested the tutorial against it.

There are plugins available for Eclipse, but we will not be using those here; instead, we'll use Maven to generate Eclipse control files for us.

Tapestry 5.2.4

You should not have to download this directly; as we'll see, Maven should take care of downloading Tapestry, and its dependencies, as needed.

Continue on to: Your First Tapestry Application



Change Notification Preferences

View Online
|
View Changes









[CONF] Apache Tapestry Tutorial

2010-11-28 Thread confluence







Tutorial
Page edited by Howard M. Lewis Ship


 Changes (5)
 



h1. Tapestry Tutorial: Introduction 
{tutorialnav} 
 
h1. Introduction  
Welcome to Tapestry!  
...
If you are reading this documentation online, be aware that the online documentation generally represents the very latest version of the code, termed quot;the snapshotquot;. The documentation is _written_ as if the next release is available, but may reference version numbers, or even features, that are only available by building the latest Tapestry source.  
[Continue on to Chapter 1: Setting Up Your Environment|Setting Up Your Environment] 
{tutorialnav} 

Full Content

FirstFormsForms2HiloSetting Up Your Environment


Introduction

Welcome to Tapestry!

This is a tutorial for people who will be creating Tapestry 5 applications. It doesn't matter whether you have experience with Tapestry 4 (or Tapestry 3, for that matter) or whether you are completely new to Tapestry. In fact, in some ways, the less you know about web development in general, and older Tapestry versions in particular, the better off you may be ... that much less to unlearn!

You do need to have a reasonable understanding of HTML, a smattering of XML, and a good understanding of basic Java language features, and a few newer things such as Java Annotations.

The Challenges of Web Application Development

If you're used to developing web applications using servlets and JSPs, or with Struts, you are simply used to a lot of pain. So much pain, you may not even understand the dire situation you are in! These are environments with no safety net; Struts and the Servlet API has no idea how your application is structured, or how the different pieces fit together. Any URL can be an action and any action can forward to any view (usually a JSP) to provide an HTML response to the web browser. The pain is the unending series of small, yet important, decisions you have to make as a developer (and communicate to the rest of your team). What are the naming conventions for actions, for pages, for attributes stored in the HttpSession or HttpServletRequest? Where do cross-cutting concerns such as database transactions, caching and security get implemented (and do you have to cut-and-paste Java or XML to make it work?) How are your packages organized ... where to the user interface classes go, and where do the data and entity objects go?  How do you share code from one part of your application to another?

On top of all that, the traditional approaches thrust something most unwanted in your face: multi-threaded coding. Remember back to Object Oriented Programming 101 where an object was defined as a bundle of data and operations on that data? You have to unlearn that lesson as soon as you build a traditional web application, because web applications are multi-threaded. An application server could be handling dozens or hundreds of requests from individual users, each in their own thread, and each sharing the exact same objects. Suddenly, you can't store data inside an object (a servlet or a Struts Action) because whatever data you store for one user will be instantly overwritten by some other user.

Worse, your objects each have only one operation: doGet() or doPost().

Meanwhile, most of your day-to-day work involves deciding how to package up some data already inside a particular Java object and squeeze that data into a URL's query parameters, so that you can write more code to convert it back if the user clicks that particular link. And don't forget editing a bunch of XML files to keep the servlet container, or the Struts framework, aware of these decisions.

Just for laughs, remember that you have to rebuild, redeploy and restart your application after virtually any change. Is any of this familiar? Then perhaps you'd appreciate something a little less familiar: Tapestry.

The Tapestry Way

Tapestry uses a very different model: a structured, organized world of pages, and components within pages. Everything has a very specific name (that you provide). Once you know the name of a page, you know the location of the Java class for that page, the location of the template for that page, and the total structure of the page. Tapestry knows all this as well, and can make things just work.

As we'll see in the following pages, Tapestry lets you code in terms of your objects. You'll barely see any Tapestry classes, outside of a few Java annotations. If you have information to store, store it as fields of your classes, not inside the HttpServletRequest or HttpSession. If you need some code to execute, it's just a simple annotation or method naming convention to get Tapestry to invoke that method, at the right time, with the right 

[CONF] Apache Tapestry IoC - coerce

2010-11-28 Thread confluence







IoC - coerce
File attached by  Bob Harner




type-coercer.png
(81 kB image/png)
-
Type Coercer diagram



   
Change Notification Preferences
   
   View Attachments









[CONF] Apache Tapestry IoC - coerce

2010-11-28 Thread confluence







IoC - coerce
Page edited by Bob Harner


Comment:
Fixed broken image, spelling, formatting, reorganized lead paragraph


 Changes (15)
 



...
{float}  
Tapestry frequently must coerce objects from one type to another. By coercion, we mean to convert an object of some type into a new object of a different type with similar content: a common example is coercing a string into an integer or a double. 
*Type Coercion* is the conversion of one type of object to a new object of a different type with similar content. Tapestry frequently must coerce objects from one type to another.  A common example is the coercion of a string into an integer or a double. 
 
Although these types of coercions happens more inside tapestry-core (inlcuding (including coercions of [component parameters|IoC - coerce]), parameters|Component Parameters]), this may also happen inside tapestry-ioc, such as when injecting a value, rather than a service, into a builder method. 
 Like everything else in Tapestry, type coercions are extensible. At the root is the [TypeCoercer|http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/services/TypeCoercer.html] service. Its configuration consists of a number of [CoercionTuple|http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/services/CoercionTuple.html]s. Each tuple defines how to coerce from one type to another. The initial set of coercions is focused primarily on coercions between different numeric types:  
!type-coercer.png! 
 
!images/type-coercer.png!Default Type Coercions Theres a few special coercions related to null there; Object -- List wraps a lone object as a singleton list, we then need null -- List to ensure that null stays null (rather than a singleton list whose lone element is a null). 
h2. Default Type Coercions 
 
There are a few special coercions related to null there; Object -- List wraps a lone object as a singleton list, we then need null -- List to ensure that null stays null (rather than a singleton list whose lone element is a null).  
Tapestry can _interpolate_ necessary coercions. For example, say it is necessary to coerce a StringBuffer to an Integer; the TypeCoercer will chain together a series of coercions:  
...
The only built-in null coercion is from null to boolean (which is always false).  
h2. Contributing nNew Coercions 
 
TypeCoercer is extensible,; you may add new coercions as desired. For example, lets say you have a {{Money}} type that represents an amount of some currency, and you want to be able to convert from {{BigDecimal}} to {{Money}. Further, lets assume that {{Money}} has a constructor that accepts a {{BigDecimal}} as its parameter. Well use a little Tapestry IOC configuration jujitsu to inform the TypeCoercer about this coercion. 
 {code:java} 
...
   }{code}  
Further, since TypeCoercer knows how to convert Double to BigDecimal, or even Integer (to Long to Double) to BigDecimal, all of those coercions would work as well. 
Further, since TypeCoercer knows how to convert {{Double}} to {{BigDecimal}}, or even {{Integer}} (to {{Long}} to {{Double}}) to {{BigDecimal}}, all of those coercions would work as well. 
 
When creating a coercion from null, use Void.class as the source type. For example, the builtin coercion from null to Boolean is implemented as: 
When creating a coercion from {{null}}, use {{Void.class}} as the source type. For example, the built-in coercion from {{null}} to {{Boolean}} is implemented as: 
 {code:java} 
...
return false; } 
}));{code} 
{code} 

Full Content

Type Coercion

Related Articles
	Parameter Type Coercion



Type Coercion is the conversion of one type of object to a new object of a different type with similar content. Tapestry frequently must coerce objects from one type to another.  A common example is the coercion of a string into an integer or a double.

Although these types of coercions happens more inside tapestry-core (including coercions of component parameters), this may also happen inside tapestry-ioc, such as when injecting a value, rather than a service, into a builder method.

Like everything else in Tapestry, type coercions are extensible. At the root is the TypeCoercer service. Its configuration consists of a number of CoercionTuples. Each tuple defines how to coerce from one type to another. The initial set of coercions is focused primarily on coercions between 

[CONF] Apache Tapestry IoC - overview

2010-11-28 Thread confluence







IoC - overview
File attached by  Bob Harner




ioc-overview.png
(97 kB image/png)
-
IoC Overview Diagram



   
Change Notification Preferences
   
   View Attachments









[CONF] Apache Tapestry IoC - overview

2010-11-28 Thread confluence







IoC - overview
Page edited by Bob Harner


Comment:
Spelling, reduced heading levels


 Changes (18)
 



...
Thats an _unmanaged_ system. Most desktop applications are unmanaged, so its a very familiar pattern, and easy to get your head around.  
By contrast, web applications are a _managed_ environment. You dont write a main(), you dont control startup. You _configure_ the Servlet API to tell it about your servlet classes to be instantiated, and their life cycle is totally controlled by the servlet container. 
 
Inversion of Control is just a more general application of this approach. The container is ultimately responsible for instantiating and configuring the objects you tell it about, and running their entire life cycle of those objects. 
 Building web applications are more complicated than monolithic applications, largely because of _multithreading_. Your code will be servicing many different users simultaneously across many different threads. This tends to complicate the code you write, since some fundamental aspects of object oriented development get called into question: in particular, the use of _internal state_, values stored inside instance variables, since in a multi-threaded environment, thats no longer the safe place it is in traditional development. Shared objects plus internal state plus multiple threads equals an broken, unpredictable application. 
...
Using unit tests, in collaboration with tools such as [EasyMock|http://easymock.org/], you can have a code base that is easy to maintain, easy to extend, and easy to test. And by factoring out a lot of _plumbing_ code, your code base will not only be easier to work with, it will be smaller.  
h12. Living on the Frontier 
 Coding applications the traditional way is like being a homesteader on the American frontier in the 1800s. Youre responsible for every aspect of your house: every board, every nail, every stick of furniture is something you personally created. There _is_ a great comfort in total self reliance. Even if your house is small, the windows are a bit drafty or the floorboards creak a little, you know exactly _why_ things are not-quite perfect. 
...
To extend the metaphor, a house in a town is not alone and self-reliant the way a frontier house is. The town house is situated on a street, in a neighborhood, within a town. The town provides services (utilities, police, fire control, streets and sewers) to houses in a uniform way. Each house just needs to connect up to those services.  
h12. The World of the Container 
 So the IoC container is the town and in the world of the IoC container, everything has a name, a place, and a relationship to everything else in the container. Tapestry calls this world The Registry.  
!images/ioc-overview.png! 
 
!images/ioc-overview.png!IoC OverviewHere were seeing a few services from the built-in Tapestry IoC module, and a few of the services from the Tapestry web framework module. In fact, there are over 100 services, all interrelated, in the Registry ... and thats before you add your own to the mix. The IoC Registry treats all the services uniformly, regardless of whether they are part of Tapestry, or part of your application, or part of an add-on library. 
 Tapestry IoCs job is to make all of these services available to each other, and to the outside world. The outside world could be a standalone application, or it could be an application built on top of the Tapestry web framework.  
h1. Service Lifecycle 
h2. Service Life Cycle 
 Tapestry services are _lazy_, which means they are not fully instantiated until they are absolutely needed. Often, what looks like a service is really a proxy object ... the first time any method of the proxy is invoked, the actual service is instantiated and initialized (Tapestry uses the term _realized_ for this process). Of course, this is all absolutely thread-safe.  
Initially a service is _defined_, meaning some module has defined the service. Later, the service will be _virtual_, meaning a proxy has been created. This occurs most often because some other service _depends_ on it, but hasnt gotten around to invoking methods on it. Finally, a service that is ready to use is _realized_. Whats nice is that your code neither knows nor cares about the life cycle of the service, because of the magic of the proxy. 
 In fact, when a Tapestry web application starts up, before it services its first request, only about 20% of the services have been realized; the remainder are defined or virtual.  
h12. Class vs. Service 
 A Tapestry service is 

[CONF] Apache Tapestry Tapestry Inversion of Control Container

2010-11-28 Thread confluence







Tapestry Inversion of Control Container
Page edited by Howard M. Lewis Ship


 Changes (1)
 



...
  public void startupService(RegistryShutdownHub shutdownHub)   { 
shutdownHub.addRegistryShutdownListener(this); 
  }  
...

Full Content

Tapestry Inversion of Control Container

Main article: Tapestry IoC

Why do I need to define an interface for my services?  Why can't I just use the class itself?

First of all: you can do exactly this, but you lose some of the functionality that Tapestry's IoC container provides.

The reason for the split is so that Tapestry can provide functionality for your service around the core service implementation.  It does this by creating proxies: Java classes that implement the service interface.  The methods of the proxy will ultimately invoke the methods of your service implementation.

One of the primary purposes for proxies is to encapsulate the service's life cycle: most services are singletons that are created just in time.  Just in time means only as soon as you invoke a method.  What's going on is that the life cycle proxy (the object that gets injected into pages, components or other service implementations) checks on each method invocation to see if the actual service exists yet.  If not, it instantiates and configures it (using proper locking to ensure thread safety), then delegates the method invocation to the service.

If you bind a service class (not a service interface and class), then the service is fully instantiated the first time it is injected, rather than at that first method invocation. Further, you can't use decorations or method advice on such a service.

The final reason for the service interface / implementation split is to nudge you towards always coding to an interface, which has manifest benefits for code structure, robustness, and testability.

My service starts a thread; how do I know when the application is shutting down, to stop that thread?

This same concern applies to any long-lived resource (a thread, a database connection, a JMS queue connection) that a service may hold onto.  Your code needs to know when the application has been undeployed and shutdown.  This is actually quite easy, by adding some post-injection logic to your implementation class.



public class MyServiceImpl implements MyService, RegistryShutdownListener
{
  private boolean shuttingDown;

  private final Thread workerThread;

  public MyServiceImpl()
  {
workerThread = new Thread(. . .);
  }

  . . .

  @PostInjection
  public void startupService(RegistryShutdownHub shutdownHub)
  {
shutdownHub.addRegistryShutdownListener(this);
  }

  public void registryDidShutdown()
  {
shuttingDown = true;

workerThread.interrupt();
  } 
}



After Tapestry invokes the constructor of the service implementation, and after it performs any field injections, it invokes post injection methods. The methods must be public and return void.  Parameters to a post injection method represent further injections ... in the above example, the RegistryShutdownHub is injected into the PostInjection method, since it is only used inside that one method.

It is not recommended that MyServiceImpl take RegistryShutdownHub as a constructor parameter and register itself as a listener inside the constructor. Doing so is an example of unsafe publishing, a remote but potential thread safety issue.

This same technique will work for any kind of resource that must be cleaned up or destroyed when the registry shuts down.

Be careful not to invoke methods on any service proxy objects as they will also be shutting down with the Registry. A RegistryShutdownListener should not be reliant on anything outside of itself.



Change Notification Preferences

View Online
|
View Changes









[CONF] Apache Tapestry Index

2010-11-28 Thread confluence







Index
Page edited by Howard M. Lewis Ship


Comment:
Make use of {div} and {div2} macros


 Changes (10)
 



...
{include:Key Features}  
{html}div id=bar{html} 
{div:id=bar} 
*We think you will love Tapestry\!* Give us 20 minutes and *[follow our quickstart guide|Getting Started]*. 
{html}/div{html} {div} 
 
{html}div id=col{html} 
{div:id=col} 
 h2. [News] [!Feed-icon.gif!|https://cwiki.apache.org/confluence/createrssfeed.action?types=blogpostspaces=TAPESTRYtitle=Apache+Tapestry+News+RSS+FeedlabelString%3Dsort=createdmaxResults=10timeSpan=12confirm=CreateshowContent=trueshowDiff=false]  {blog-posts:max=10|sort=creation|reverse=true|content=excerpts} 
{html}/div{html} {div} 
 
{html}div id=content class=big-col{html} 
{div:id=content|class=big-col} 
 h2. What is Apache Tapestry? 
...
[Cubiculus|http://www.cubiculus.com] : Lego Building Instructions  
{html}div class=clearer/div/div /divdiv class=clearer/div{html} 
{div2:class=clearer} {div2} {div2:class=clearer} {div2} {div} 

Full Content



  

  
  Component oriented framework for creating dynamic, robust, highly scalable web applications in Java.
  




	Java Power

Tapestry pages and components are simple Java POJOs, with easy access to all Java language features and the vast Java ecosystem. Thanks to Java's advanced concurrency API, Tapestry handles requests fast without sacrificing security or stability.

	Scripting Ease

Tapestry features live class reloading: change your Java code, refresh the browser and see the changes... instantly! Have your cake and eat it too: the speed and depth of Java, the agile development style of Ruby or Python.

	Highly Productive

Simple POJO classes, streamlined templates, live class reloading, state-of-the-art exception reporting, first-class Ajax support, and a big library of built-in components: Tapestry is designed from the ground up to give you great productivity.






We think you will love Tapestry Give us 20 minutes and follow our quickstart guide.


News 




Friday, 19 November 2010



Live Tapestry Hotel Booking Demo


Last changed Nov 20, 2010 04:21 by Christophe Cordenier


 Curious to see a real Tapestry application live?  Your wish is fulfilled; the Hotel Booking Demo is now available.

Read more

Posted at Nov 19, 2010 by

Howard M. Lewis Ship|

0 comments
|
Edit





Thursday, 18 November 2010



Tapestry 5.2.4 beta release


Last changed Nov 18, 2010 17:03 by Howard M. Lewis Ship


 Following a successful vote, the Tapestry team has released the latest (and likely, final) beta release of Tapestry 5.2, version 5.2.4. 

This release consists of a modest number of bug fixes to 5.2.2, along with a few non-disruptive last minute improvements. Full release notes are available. 

Read more

Posted at Nov 18, 2010 by

Howard M. Lewis Ship|

0 comments
|
Edit





Sunday, 31 October 2010



Tapestry 5.2.2 beta release


Last changed Nov 07, 2010 14:24 by Andreas Andreou


 Following a successful vote, the Tapestry team has released the second beta release of Tapestry 5.2, version 5.2.2.

This release consists of a modest number of bug fixes to 5.2.1, along with a few non-disruptive last minute improvements. Full release notes are available.

Read more

Posted at Oct 31,