Rainy days and Java always get me down

I've Moved My Blog

It's currently located at http://www.urlinone.com/blog

I should say "I'm moving my blog." It's a pretty painful process.

Pebble has blown up on me, and it's been many months since I've been able to blog reliably. I've lost posts. And now I've got to figure out how to migrate my past blog posts from Pebble to my new destination without all the URLs changing, lest external links become 404 Not Founds.

Why does everything in the 21st century have to be a three-day project???

Maybe it was the fact that I had just come off of nitrous oxide..., uh, because I had just had, uh, dental work, yeah, that's it, I had just had dental work, yeah, dental work! That's the ticket! Anyway, I would swear that Weird Al Yankovich came to the Atlanta Java Users Group meeting last week to talk about Tapestry. But that's probably just the nitrous talking.

In my susceptible state, Howard Lewis Ship convinced me that Tapestry was a very powerful web layer and superior alternative to Struts (not hard to convince me of that!), WebWork, Spring MVC, and all the other MVC frameworks now competing for our attention. I have to say, I think I agree. Tapestry takes a different approach from all the other MVC frameworks, and you end up with clean, succinct, and nice-looking code and web pages. I think I've found my presentation layer of choice -- at least until I start hunting for just the right RIA platform with which to drive myself nuts. Quick, where's that nitrous?!

Anyway, I was able to integrate Tapestry 3.0 into AppFuse 1.5, effectively tripling my version number to 4.5, which was quite a coup. Here's how I did it...

The first step is to add the tapestry jar to the classpath. To do this, you must copy the jar and edit two files.

1. Create directory Tapestry-3.0 under the lib directory.

2. Copy tapestry-3.0.jar into lib/Tapestry-3.0.

3. Edit lib/lib.properties, adding the following at the very bottom of the file:

# Tapestry - http://jakarta.apache.org/tapestry
tapestry.version = 3.0

4. Edit properties.xml. Locate the line that says

<path id="web.compile.classpath">

5. Go down about 17 lines, and just before the line that says


add the following line:

    <fileset dir="${tapestry.dir}" includes="*.jar"/>

Now, all jar files in lib/Tapestry-3.0 will be part of the classpath when compiling the web module.

Next, we have to change the deployment descriptors to allow Tapestry's servlet to run and for certain URLs to reach it.

1. Add the following to the bottom of metadata/web/servlets.xml:

    <!-- Tapestry Servlet Configuration -->

2. Add the following to the bottom of metadata/web/servlet-mappings.xml:

    <!-- Tapestry Servlet Mapping -->

3. Add the following to the top of metadata/web/web-security.xml:

    <!-- Grant access to public areas -->
            <description>Tapestry Pages</description>

We've now added the Tapestry servlet, mapped all URLs with an .htm extension to it, and granted free access to these pages without having to be logged in via AppFuse's security model. Enabling security is outside the scope of this document.

Next, we'll add a simple Tapestry page to the application:

1. Create a file called Home.java in src/web/org/appfuse/webapp:

package org.appfuse.webapp;

import java.util.Date;
import org.apache.tapestry.html.BasePage;

public class Home extends BasePage {
	public Date getCurrentDate() {
		return new Date();

2. Create a file called Home.html in web/WEB-INF:

   This application demonstrates some dynamic 
   behavior using Tapestry components.
   The current date and time is: 
   <b><span jwcid="insertDate">This Text Will Be Replaced</span></b>
   Click <a jwcid="refresh">here</a> to refresh.

3. Create a file called Home.page in web/WEB-INF:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE page-specification
      PUBLIC "-//Apache Software Foundation//Tapestry Specification 3.0//EN"

    <description>Simple Home Page</description>

	<component id="insertDate" type="Insert">
		<binding name="value" expression="currentDate"/>
	<component id="refresh" type="PageLink">
		<static-binding name="page">Home</static-binding>

If you read one of the many Tapestry tutorials, you will not have a difficult time understanding this exceedingly simple Tapestry page. I highly, highly recommend this free sample chapter from Tapestry in Action.

One note about Tapestry and accompanying jars:

I had to manually retrieve a couple of jars that I would have thought Tapestry would include automatically. Namely, I had to download and copy the jars for OGNL and Javassist, since Tapestry referred to them, but they were not included in the Tapestry install. Maybe it's a licensing thing? Anyway, I put all the jars in my $CATALINA_HOME/common/lib directory, rather than putting them into my AppFuse lib area. I guess either way will work, but who needs the monster war every time you build? But you do need the tapestry-3.0.jar in the web.compile.classpath to resolve external references.

Now, all you have to do is ant deploy start.tomcat, and your AppFuse project should be unchanged, other than the addition of the Tapestry page at http://localhost:8080/appfuse/Home.htm. You should be able to add a link to this URL within your Struts pages in AppFuse and jump back and forth, although I am sure that there are all kinds of ugly issues with session state once you start doing anything meaningful.

That's as far as I've gone with this, so there are probably plenty of issues to deal with in this mutant, hybrid environment. Matt Raible plans on adding a Tapestry version of AppFuse some time in late 2004, but this allows you to at least play with Tapestry today. Have fun, and feel free to post problems, suggestions, and enhancements!

ahhh the nitrous, had many a fun nights with my tank.. anyhow.. ive been playing with tapestry for 2 days and its really well uhm.. different, just been trying different things out, reading lots of source, and found a couple of basic tutorials, still dont know what the best practices are but it looks really good but theres just so much to learn, its like an all-in-one framework, instead of using different frameworks together like sitemesh,webwork2,displaytag, etc i just need one, anyhow, its been alot of fun learning it and i've got to buy the book and im really excited about it because its just so different, but right now im pretty dammed happy with sitemesh and webwork2, plus spring, hibernate, velocity, all these neat frameworks, and so many more to look into..
Hi Lee, Thank for turning me on to Appfuse and Tapestry. I tried your instructions for adding Tapestry. I'm using Tomcat 5.0 and have some notes: <p> TYPO: The new file is saved as Home.htm , not .html <p> I also added this to build.xml in the package-web target , war task: <p> <lib dir="${tapestry.dir}"/> <p> The I got some ClassNotFoundExceptions and added these 2 jars to CATALINA_HOME/common/lib <br> <a href="http://cvs.apache.org/dist/jakarta/bsf/v2.3.0rc1/bin/">bsf.jar</a> <br> <a href="http://jakarta.apache.org/site/binindex.cgi"> commons-codec-1.3.jar</a> <p> Now I'm getting this error: <pre> Could not load class org.appfuse.webapp.Home from WebappClassLoader delegate: false repositories </pre> <p> and I'm in no mood to think about classloader problems. Never have been. My brain shuts down when I see the phrase ClassLoader. I'll check back with you when it kicks in again. <p> Mike
Lee Grey shows how to integrate Tapestry into AppFuse . Good stuff Lee. I can't wait to pump out the the WebWork version of AppFuse so I can start on Tapestry integration. Then again, I do have it on the roadmap to take a break after 1.6. I hope t

Add a comment

HTML : b, i, blockquote, br, p, pre, a href="", ul, ol, li
E-mail address
Remember me Yes  No 

E-mail addresses are not publicly displayed, so please only leave your e-mail address if you would like to be notified when new comments are added to this blog entry (you can opt-out later).

TrackBack to http://www.leegrey.com/hmm/addTrackBack.action?entry=1093309508000