Hi,
If you know how to build pages, then you (largely) know how to build
components. A page is just a specialized component.
Here are the main differences:
* Components go in the .components package (instead of .pages)
* Component templates are optional because a component may choose to do all
of its rendering via code. However, if your component will make use of other
components, then your component will need a template.
** Note that component templates must be in the same package as the
component class file.
* Components can have parameters (via the @Parameter) annotation.
So in your case, it might look something like:
CountrySelect.tml:
<t:container xmlns:t="http://tapestry.apache.org/schema/tapestry_5_2_0.xsd">
<t:select t:id="countrySelect" model="countryModel" value="value"/>
</t:container>
CountrySelect.java
import ...;
public class CountrySelect {
@Parameter(required=true)
@Property
private Object value;
public SelectModel getCountryModel() {
//do your lookup and return the model...
}
}
That's the core...
As an alternative, you could simply write a "CountrySelectModel" and just use
<t:select> with your custom model anywhere you need it.
Robert
On Dec 15, 2010, at 12/1511:47 AM , hese wrote:
>
> Hi,
>
> Can any one tell me where I can find a T5 example of how to build a custom
> component and what the different files I should create are?
>
> My need is - I have a select box that populates from a database (Something
> like a country list...). And I want to be able to include this select box
> in any tml that I want and have the box populated with the lookup values.
>
> Thanks!
>
>
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/How-to-create-a-custom-component-tp3306682p3306682.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]