Hi Andrew,

Historically, our response to this question has been that it is not supported 
because WTKX is primarily about defining the structure of a UI, not the 
behavior. Passing arguments in this way implies logic, which we have generally 
delegated to code rather than markup. However, since it has come up more than 
once, it may be worth considering. I think the strongest argument in favor of 
adding such a feature is that you can actually pass arguments to the root WTKX 
file via the put() method of WTKXSerializer, even though you can't currently 
pass them to nested WTKX files.

Feel free to submit a feature request to add this capability. You can file it 
against Pivot 1.5.1.

Thanks,
Greg

P.S. I saw your post on Stack Overflow where you mentioned trying to extending 
TablePane.Row - in Pivot 1.5, this class is no longer final, so you can 
actually do this now.


On Apr 25, 2010, at 7:44 PM, Andrew Swan wrote:

> Hello,
> 
> I'm a first-time poster and new Pivot user, so be gentle!
> 
> I need to create a custom 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 <wtkx:include> 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? 
> 
> Andrew

Reply via email to