Thiago,
I was just about to write my solution up in the Wiki, but I'm having
problems getting my password to work :-(
Anyway, yes, you're quite right, you can extend component classes.
My main job was to supply a GridEx.tml where I added my special link:
<div class="t-data-grid"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
<table t:id="table">
<thead>
<tr class="GridExHeader">
<td colspan="${pagerCols}"><div t:id="pagerTop"/></td>
<td class="t-last"><a t:type="CSVImageLink" t:source="inherit:source"
t:model="inherit:model" t:filename="literal:kunden"></a></td>
</tr>
<tr t:id="columns"/>
</thead>
<tbody>
<tr t:id="rows"/>
</tbody>
</table>
<div t:id="pagerBottom"/>
<t:block>
<div t:id="pager"/>
</t:block>
<t:block id="empty">There is no data to display.</t:block>
</div>
I added getPagerCols to the GridEx class, and bingo, it all worked!
Thanks for the ideas, but in this case, I think it was easier to just
provide a tml file.
Ciao,
Jonathan
On 06/07/2009 15:45, Thiago H. de Paula Figueiredo wrote:
n Mon, Jul 6, 2009 at 10:20 AM, Jonathan O'Connor<ninki...@eircom.net> wrote:
Hi,
Hi!
I'm pretty sure what the answer is, but can someone confirm that it is not
possible to use java inheritance to extend a component class?
Yes, it is.
What I'm trying to do is add a CSV Download button to a Grid, preferably
aligned to the right of the table. I can override the .tml files of the
existing components, but I would prefer to not have to duplicate all the
java code from the Grid class.
Tapestry built-in components have most of their method package-private
or private for backward compatibility, so subclassing them isn't the
answer most of the time.
I considered using a mixin, but that does not allow the mixin to create
other components. Or have I got that wrong?
Just Tapestry itself can instantiate components, so I guess you got
something wrong here.
And I think a mixin it's the best way of doing what you want:
@InjectContainer the Grid, use Grid.getGridDataSource(),
Grid.getDataModel() (to get the BeanModel), maybe
Grid.getCurrentPage(), create an EventLink and return a StreamResponse
in its handler method. Take a look at the Autocomplete mixin source
for inspiration. No need for subclassing here.
Another example, but more complex:
http://ars-machina.svn.sourceforge.net/viewvc/ars-machina/tapestry-crud/branches/1.1/src/main/java/br/com/arsmachina/tapestrycrud/mixins/TreeGrid.java?revision=594&view=markup.
It is a mixin that provides a tree-like visualization to a Grid.