I have been using Tapestry’s built-in components, but now I’d like to try making my own. Assuming this is possible, how is it done and is it generally expected that developers are going to be creating their own components in addition to what comes out of the box?
Share
Yes it is expected that developers will create their own components and it is pretty easy to do. There are quite a few projects out there where people are creating their libraries of components. If you want to see some examples take a look at:
Components are much like pages. They usually have a .tml file and a .java file. The .java file goes in a src directory called components (src/main/java/com/examples/app/components) and the .tml file goes in the same place, but under resources (src/main/resources/com/examples/app/components)
Here is an example of a component that renders as a Facebook share link that links to the EventInfo page and takes an Event object in order to construct the URL to share on Facebook.
Pay particular attention to how the Event property is annotated to mark it as a required Parameter. This makes it a parameter of your component so you can call it from a template saying
<t:shareeventonfacebook event="myEvent"/>And the corresponding template file:
You want to use the component in your page template you use: