Thursday, March 18, 2010

Tapestry 5 and Netbeans 6.8

There are a few pages on the internet about setting up Tapestry 5 on Netbeans 6.8.

I did manage to get it work with the Netbeans Maven plugin (as opposed to installing the maven package). I don't know much about Maven, but the whole repository thing sounds a bit too slick for me. At the scale of development I'm doing, there's no question it is overkill.

In order to set the new application I just did created a regular java web app. This is based on the "Tapestry 5, Netbeans 6.5" page at old.nabble.com. Using the regular Tapestry 5.0.5 download I created a library with the following jars in it:

antlr-runtime-3.1.1.jar
commons-codec-1.3.jar
javassist-3.9.0.GA.jar
log4j-1.2.14.jar
slf4j-api-1.5.2.jar
slf4j-log4j12-1.5.2.jar
stax2-api-3.0.1.jar
stax-api-1.0.1.jar
tapestry5-annotations-5.1.0.5.jar
tapestry-core-5.1.0.5.jar
tapestry-ioc-5.1.0.5.jar
woodstox-core-asi-4.0.3.jar


The application is called "test" in the following examples.

Setup your web.xml to look something like this (set the applicaton name):

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>Test Application</display-name>
<context-param>
<param-name>tapestry.app-package</param-name>
<param-value>test</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<filter>
<filter-name>app</filter-name>
<filter-class>org.apache.tapestry5.TapestryFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>app</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>


You might as well delete the index.jsp file.

In Web Pages folder, create an empty file called Start.tml:


<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
<head>
<title>Start Page</title>
</head>
<body>
<h1>Start Page (Start.tml/Start.java)</h1>
<p> The current time is: ${currentTime}. </p>
<p>
[<t:pagelink t:page="Start">Refresh</t:pagelink>]
</p>
</body>
</html>


In the Source Packages folder create project called "test.pages". If you are going to do anything serious here, you might as well create a "test.components" package because you will need that to build any sort of application. Other locations can be used for other classes.

In "test.pages" create java class "Start.java":

package test.pages;
import java.util.Date;

public class Start {
public Date getCurrentTime() {
return new Date();
}
}


By the way these examples above would look better with indenting. I'm afraid I don't see a way to do this with blogspot. To bad you couldn't just wrap stuff in a pre tag.

Make sure you add the library with those jars listed above in it, then build and then run. If you didn't remove the index.jsp you will get a "Hello World". If not you'll get a demo screen showing the current time (so you know it is real :-)).

No comments:

Post a Comment