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.
- 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.