Tapestry 5 – 10 Minute Demo of Apache Tapestry

by Mark Shead on February 14, 2011

This is a demonstration of about 10 minutes of programming in Tapestry 5 creating a sample application. The app is pretty basic and just lets you add URLs to a list and then vote on them-similar to the idea behind Digg or Reddit. I didn’t really explain things in great detail so it is more of a demonstration of some of the things you can do than it is a step by step tutorial.


General steps in making the application:

  • Create a Quickstart application from the Maven archetype.
  • Add the dependencies and configs for Hibernate.
  • Create an Item entity to store our url, title, and number of votes.
  • Use a BeanEditForm and onSuccess method to create Items.
  • Use a Loop to show the items in the database
  • Use an ActionLink and onActionFromVote method to count the votes
  • Add onValidate method to do validate the URLs.
  • Stick the loop in a Zone and update it with the ActionLink

The app uses the Quickstart archetype from 5.3 so it uses the new green theme.

Errata

  • I used @Component on the BeanEditForm, but I should have used @InjectComponent. As you can see in the comments, Howard isn’t really sure why this worked. So use @InjectComponent instead.
  • The zone should have gone around the ul elements instead of within it. The zone renders as a div and we shouldn’t have a div inside of the open/close ul.

About 

{ 9 comments… read them below or add one }

Howard M. Lewis Ship February 15, 2011 at 10:47 pm

Very nice, just a couple of notes:

I tend to use no visibility modifier (that is, “package private”) for my event handler methods.

On the Zone, I would have placed the t:zone around the <ul> I’m not sure you are rendering valid HTML putting the between the <ul> and the <li> elements.

Lastly, I’m surprised the @Component annotation worked in your situation, you should use @InjectComponent when the component type is determined from the template, as in this case (i.e., <t:beaneditfor>

Reply

Mark Shead February 15, 2011 at 10:57 pm

Thank you for the suggestions. This was a bit of a learning experience for me, and I appreciate the feedback.

Reply

Christopher Dodunski February 16, 2011 at 1:45 am

Hi Mark,

To a Tapestry greenhorn like me, video tutorials such as yours are a breath of fresh air. And you cover the vitals, such as Tapestry form persisted to database via Hibernate. Are you keen enough to produce an IntelliJ IDEA/Tomcat version?

Kind regards,

Chris.

Reply

Thiago February 16, 2011 at 1:02 pm

Hi, Mark!

Another suggestion: use EventLink instead of ActionLink, which is sort of deprecated now.

Good job!

Reply

Ambrose Little February 24, 2011 at 9:53 am

Hi Mark,

Looks good. You have a pleasant recording voice, and the pace was about right–maybe a tiny bit fast for n00bs. You make it look easy, which is nice.

In terms of UX, I guess that’s not the point here, but I’d try for something a bit more explanatory than “Invalid URL”; also I don’t recall if it indicates in the form where the problem is. Also, I’m a bit ambivalent about the automatic re-ordering of the list while you’re clicking on it–felt a bit too sudden, which could be disorienting to people. Plus, if they wanted to vote twice (if that’s allowed), they might think “I can click click” and then find they voted for the wrong one because it moved–so you might add a delay.

Lastly, the vid ended very suddenly. I’d suggest a short recap/goodbye at the end.

Again, overall, I thought it was very well done, easy to follow, and pleasant. Thanks.

Reply

Patrick May 19, 2011 at 6:24 pm

I followed your example and found that onValidate does not work with Tapestry 5. However onValidateForm does.

Reply

Patrick May 19, 2011 at 6:32 pm

Oh, and forgot to mention Excellent Demo! You didn’t miss a step and your presentation was good, even when you forgot to mark properties as private. Presenting errors definitely helps.

Thanks for doing this.

Reply

Jenny July 25, 2012 at 6:12 pm

I like this tutorial , Can you send for me the source code
Thank you very much

Jenny

Reply

Mark Shead August 7, 2012 at 11:48 pm

Leave a Comment

Previous post:

Next post: