You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Jonathan O'Connor <ni...@eircom.net> on 2009/07/06 15:20:56 UTC
Inheriting from Component Classes
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?
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.
I considered using a mixin, but that does not allow the mixin to create
other components. Or have I got that wrong?
I feel this is a pain point for Tapestry. Is there any work going on to
improve this area? Of course, for smaller components, I wouldn't worry
about it, but the Grid component is large, and has lots of useful
functionality I don't want to duplicate. One possibility, specific to
Grid would be to add more block parameters that could be used to extend
the layout of the Grid. Would this work for me?
Thanks for any advice,
Jonathan O'Connor
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Inheriting from Component Classes
Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Mon, Jul 6, 2009 at 12:05 PM, Jonathan O'Connor<ni...@eircom.net> wrote:
> Thiago,
Hi!
> Thanks for the ideas, but in this case, I think it was easier to just
> provide a tml file.
You're welcome!
And thanks for giving me the idea of creating a CSV/HTML/whatever
export mixin for Grids. :)
--
Thiago
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Inheriting from Component Classes
Posted by Jonathan O'Connor <ni...@eircom.net>.
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<ni...@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.
>
>
Re: Inheriting from Component Classes
Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
n Mon, Jul 6, 2009 at 10:20 AM, Jonathan O'Connor<ni...@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.
--
Thiago
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org