How to pass parameters to Apache Pivot's wtkx:include tag?

Posted by Andrew Swan on Stack Overflow See other posts from Stack Overflow or by Andrew Swan
Published on 2010-04-25T23:49:26Z Indexed on 2010/04/25 23:53 UTC
Read the original article Hit count: 308

Filed under:

I need to create a reusable UI component that accepts a number of parameters (e.g. an image URL and some label text), similar to how JSP tags can accept parameters. The Pivot docs for the "wtkx:include" tag say:

The tag allows a WTKX file to embed content defined in an external WTKX file as if it was defined in the source file itself. This is useful for ... defining reusable content templates

I was hoping that I could define my component in a WTKX file using standard Pivot components (e.g. a TextInput) and pass it one or more parameters; for example my reusable template called "row.wtkx" might contain a row with an image and a text field, like this (where the ${xxx} bits are the parameters):

<TablePane.Row xmlns="org.apache.pivot.wtk">
    <ImageView image="@images/${image_url}" />
    <TextInput text="${title}" />
</TablePane.Row>

I could then reuse this component within a TablePane as follows:

<rows>
    <TablePane.Row>
        <Label text="Painting"/>
        <Label text="Title"/>
    </TablePane.Row>
    <wtkx:include src="row.wtkx" image_url="mona_lisa.jpg" title="Mona Lisa"/>
    <wtkx:include src="row.wtkx" image_url="pearl_earring.jpg" title="Girl with a Pearl Earring"/>
    <wtkx:include src="row.wtkx" image_url="melting_clocks.jpg" title="Melting Clocks"/>
</rows>

I've made up the ${...} syntax myself just to show what I'm trying to do. Also, there could be other ways to pass the parameter values other than using attributes of the "wtkx:include" tag itself, e.g. pass a JSON-style map called say "args".

The ability to pass parameters like this would make the include tag much more powerful, e.g. in my case allow me to eliminate a lot of duplication between the table row declarations.

Or is "wtkx:include" not the right way to be doing this?

© Stack Overflow or respective owner

Related posts about apache-pivot