You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Alfie Kirkpatrick <Al...@ioko.com> on 2009/07/06 18:36:16 UTC

Mixin to grid component - adding columns

Hi, I'd like to write a mixin to the grid component which adds a column
which is under the control of the mixin. In my case it's a checkbox
column where the selected state is held by the mixin. Not sure if this
is ultimately going to work (well) but am seeing how far I can take
it...

 

So the TML might look like this:

 

<t:grid t:id="mygrid" source="mysource" row="current"
t:mixins="selectablegrid" selectionkey="current.id">

   ...

</t:grid>

 

I tried simply adding a new field using
grid.getDataModel().add("mynewcolumn") but, not surprisingly, it fails
saying that this is not a property of the source bean!

 

Am trying to see where the grid component processes informal parameters
which is the TML way of adding an adhoc column to the grid. Am assuming
once I can find this I can delegate rendering to a block defined by my
mixin's TML.

 

Any help appreciated,

Alfie.


Re: Mixin to grid component - adding columns

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
You're right, Robert. Maybe there should be a distinction between  
<t:parameter>-style informal parameters and the HTML attribute ones, so we  
don't have the confusion we had here.

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Mixin to grid component - adding columns

Posted by Robert Zeigler <ro...@scazdl.org>.
Just because grid is using the parameters in a different way doesn't  
make them any less informal.  Nor does the fact that this particular  
use of an informal parameter is documented make them any less  
informal.  :)

From:
http://tapestry.apache.org/tapestry5.1/cookbook/informals.html

"Informal parameters are additional parameters beyond the formal  
parameters defined for a component using the Parameter annotation."

By definition, then, the <t:parameter name="propertyId"> (or, for 5.1:  
<p:propertyId>) parameters used by grid are informal, since they  
aren't declared by the @Parameter annotation. And, I might add, that  
if the Grid ceased using the @SupportsInformalParameters annotation,  
this very nice functionality of grid would disappear.  So, they are  
very much informal parameters.  Although a component will /usually/  
render informal parameters directly as element attributes, there's no  
requirement that it do so; it can use them any way it wants.   
Arguably, the "peculiar" use of informal parameters by grid warrants  
documentation precisely because it uses them in so atypical a  
fashion.  But to the framework, they are still informal parameters.

Cheers,

Robert

On Jul 6, 2009, at 7/61:02 PM , Thiago H. de Paula Figueiredo wrote:

> Em Mon, 06 Jul 2009 14:23:41 -0300, Robert Zeigler  
> <ro...@scazdl.org> escreveu:
>
>> Actually, Thiago, he's right about grid.
>> <t:grid ...>
>>   <t:parameter name="somecolumnname">
>>     special rendering here
>>   </t:parameter>
>> </t:grid>
>>
>> "somecolumnname" is really just an informal parameter,
>
> I'm sorry, Robert, but I think it isn't an *informal* parameter as  
> it's defined by the documentation nor the use this expression has in  
> the API (ComponentResources.renderInformalParameters()). Informal  
> parameters are about HTML tag attributes.
> IMHO, the above example is a parameter, but not an informal one.
>
> -- 
> Thiago H. de Paula Figueiredo
> Independent Java consultant, developer, and instructor
> http://www.arsmachina.com.br/thiago
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Mixin to grid component - adding columns

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Mon, 06 Jul 2009 14:23:41 -0300, Robert Zeigler <ro...@scazdl.org>  
escreveu:

> Actually, Thiago, he's right about grid.
> <t:grid ...>
>    <t:parameter name="somecolumnname">
>      special rendering here
>    </t:parameter>
> </t:grid>
>
> "somecolumnname" is really just an informal parameter,

I'm sorry, Robert, but I think it isn't an *informal* parameter as it's  
defined by the documentation nor the use this expression has in the API  
(ComponentResources.renderInformalParameters()). Informal parameters are  
about HTML tag attributes.
IMHO, the above example is a parameter, but not an informal one.

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Mixin to grid component - adding columns

Posted by Robert Zeigler <ro...@scazdl.org>.
Actually, Thiago, he's right about grid.
<t:grid ...>
   <t:parameter name="somecolumnname">
     special rendering here
   </t:parameter>
</t:grid>

"somecolumnname" is really just an informal parameter, albeit one that  
grid will explicitly search for (actually, it's not grid that does the  
searching, directly, it's one of the components contained by grid,  
ultimately GridCell (an extension of AbstractPropertyOutput). But the  
search for the parameter is done via the "overrides" parameter, so  
that's the parameter that you need to specify.

Robert

On Jul 6, 2009, at 7/612:07 PM , Thiago H. de Paula Figueiredo wrote:

> Em Mon, 06 Jul 2009 13:36:16 -0300, Alfie Kirkpatrick <Alfie.Kirkpatrick@ioko.com 
> > escreveu:
>
>> I tried simply adding a new field using
>> grid.getDataModel().add("mynewcolumn") but, not surprisingly, it  
>> fails
>> saying that this is not a property of the source bean!
>
> Try add("mynewcolumn", null). If you don't pass the second  
> parameter, BeanModelSource thinks it is a property of the class  
> being listed (aka the objects inside the collection or  
> GridDataSource passed to the source parameter).
>
>> Am trying to see where the grid component processes informal  
>> parameters
>> which is the TML way of adding an adhoc column to the grid.
>
> I guess you're not right about what informal parameters are. Quoting http://tapestry.apache.org/tapestry5.1/guide/parameters.html 
> :
>
> "Some components support informal parameters, additional parameters  
> beyond the formally defined parameters. Informal parameters will be  
> rendered into the output as additional attributes on the tag  
> rendered by the component. Generally speaking, components that have  
> a 1:1 relationship with a particular HTML tag (such as TextField and  
> <input> will support informal parameters."
>
> This is used, for example, in the link components, so you can set  
> the <a> tag class attribute and have it rendered. Informal  
> parameters are rendered this way:
>
> @Inject
> private ComponentResources resources;
>
> resources.renderInformalParameters(writer);
>
>> Am assuming
>> once I can find this I can delegate rendering to a block defined by  
>> my
>> mixin's TML.
>
> Just create a parameter in your mixin. To pass a value to it, just  
> add it as a parameter to the component that has the mixin.
> Example from the FormFragment component, used together with the  
> TriggerFragment mixin:
>
> <t:checkbox t:id="separateShipTo" t:mixins="triggerfragment"  
> fragment="seperateShippingAddress"/>
>
> fragment is a TriggerFragment parameter, not a Checkbox one nor an  
> informal parameter.
>
> -- 
> Thiago H. de Paula Figueiredo
> Independent Java consultant, developer, and instructor
> http://www.arsmachina.com.br/thiago
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Mixin to grid component - adding columns

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Mon, 06 Jul 2009 13:36:16 -0300, Alfie Kirkpatrick  
<Al...@ioko.com> escreveu:

> I tried simply adding a new field using
> grid.getDataModel().add("mynewcolumn") but, not surprisingly, it fails
> saying that this is not a property of the source bean!

Try add("mynewcolumn", null). If you don't pass the second parameter,  
BeanModelSource thinks it is a property of the class being listed (aka the  
objects inside the collection or GridDataSource passed to the source  
parameter).

> Am trying to see where the grid component processes informal parameters
> which is the TML way of adding an adhoc column to the grid.

I guess you're not right about what informal parameters are. Quoting  
http://tapestry.apache.org/tapestry5.1/guide/parameters.html:

"Some components support informal parameters, additional parameters beyond  
the formally defined parameters. Informal parameters will be rendered into  
the output as additional attributes on the tag rendered by the component.  
Generally speaking, components that have a 1:1 relationship with a  
particular HTML tag (such as TextField and <input> will support informal  
parameters."

This is used, for example, in the link components, so you can set the <a>  
tag class attribute and have it rendered. Informal parameters are rendered  
this way:

@Inject
private ComponentResources resources;

resources.renderInformalParameters(writer);

> Am assuming
> once I can find this I can delegate rendering to a block defined by my
> mixin's TML.

Just create a parameter in your mixin. To pass a value to it, just add it  
as a parameter to the component that has the mixin.
Example from the FormFragment component, used together with the  
TriggerFragment mixin:

<t:checkbox t:id="separateShipTo" t:mixins="triggerfragment"  
fragment="seperateShippingAddress"/>

fragment is a TriggerFragment parameter, not a Checkbox one nor an  
informal parameter.

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


RE: Mixin to grid component - adding columns

Posted by Alfie Kirkpatrick <Al...@ioko.com>.
Thanks Robert that all makes sense to me. Had a funny feeling I was going to run up against TAP5-103 again on this one ;-)

Regards, Alfie.

-----Original Message-----
From: Robert Zeigler [mailto:robertz@scazdl.org]
Sent: Mon 06/07/2009 18:18
To: Tapestry users
Subject: Re: Mixin to grid component - adding columns
 
This is an interesting idea, although I'm not sure if it will work  
(see point #2)

1) you want to use:

grid.getDataModel().add("mynewcolumn",null);

which will inform the data model that you're adding a column that  
doesn't correspond (directly) to a property.
Alternatively, you can provide a PropertyConduit implementation  
instead of null.

2) Mixins can't use tml.  This will complicate things a bit because  
the grid is going to look for a way to render the column and not find  
it... but I wonder if there's a way get around this.
Certainly, your page or component's tml file could define the  
appropriate parameter block, but, that's a bit silly since it  
basically defeats the point of the mixin.
What you /might/ be able to do is define some sort of "MixinBlocks"  
page that your mixins all use to define their blocks.  Certainly, you  
can do that and delegate rendering to a block in any arbitrary page  
normally... the trick comes in hooking this block up for Grid.

Grid provides an "overrides" parameter that would let you do the  
trick, except... there's really not any way for you to specify it from  
within the mixin, yet. https://issues.apache.org/jira/browse/TAP5-103  
would help a lot, but I'm still exploring the best way to implement  
this.
In the meantime, perhaps you could create a custom implementation of  
PropertyOverrides that you supply to the grid whenever you're using  
the mixin.  It's a little ugly that you have to specify this, but at  
least the logic could then be encapsulated in a single place.  This  
implementation would need to lookup up the block in the page/grid, as  
well as any other appropriate locations (a MixinBlocks page, for  
instance).  Probably the simplest implementation would extend the  
current PropertyOverridesImpl implementation and take the grid  
component resources as input, but do a search first within any other  
"special" pages (MixinBlocks, etc.), then fallback to searching the  
grid parameters.

HTH,

Robert


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Mixin to grid component - adding columns

Posted by Robert Zeigler <ro...@scazdl.org>.
This is an interesting idea, although I'm not sure if it will work  
(see point #2)

1) you want to use:

grid.getDataModel().add("mynewcolumn",null);

which will inform the data model that you're adding a column that  
doesn't correspond (directly) to a property.
Alternatively, you can provide a PropertyConduit implementation  
instead of null.

2) Mixins can't use tml.  This will complicate things a bit because  
the grid is going to look for a way to render the column and not find  
it... but I wonder if there's a way get around this.
Certainly, your page or component's tml file could define the  
appropriate parameter block, but, that's a bit silly since it  
basically defeats the point of the mixin.
What you /might/ be able to do is define some sort of "MixinBlocks"  
page that your mixins all use to define their blocks.  Certainly, you  
can do that and delegate rendering to a block in any arbitrary page  
normally... the trick comes in hooking this block up for Grid.

Grid provides an "overrides" parameter that would let you do the  
trick, except... there's really not any way for you to specify it from  
within the mixin, yet. https://issues.apache.org/jira/browse/TAP5-103  
would help a lot, but I'm still exploring the best way to implement  
this.
In the meantime, perhaps you could create a custom implementation of  
PropertyOverrides that you supply to the grid whenever you're using  
the mixin.  It's a little ugly that you have to specify this, but at  
least the logic could then be encapsulated in a single place.  This  
implementation would need to lookup up the block in the page/grid, as  
well as any other appropriate locations (a MixinBlocks page, for  
instance).  Probably the simplest implementation would extend the  
current PropertyOverridesImpl implementation and take the grid  
component resources as input, but do a search first within any other  
"special" pages (MixinBlocks, etc.), then fallback to searching the  
grid parameters.

HTH,

Robert

On Jul 6, 2009, at 7/611:36 AM , Alfie Kirkpatrick wrote:

> Hi, I'd like to write a mixin to the grid component which adds a  
> column
> which is under the control of the mixin. In my case it's a checkbox
> column where the selected state is held by the mixin. Not sure if this
> is ultimately going to work (well) but am seeing how far I can take
> it...
>
>
>
> So the TML might look like this:
>
>
>
> <t:grid t:id="mygrid" source="mysource" row="current"
> t:mixins="selectablegrid" selectionkey="current.id">
>
>   ...
>
> </t:grid>
>
>
>
> I tried simply adding a new field using
> grid.getDataModel().add("mynewcolumn") but, not surprisingly, it fails
> saying that this is not a property of the source bean!
>
>
>
> Am trying to see where the grid component processes informal  
> parameters
> which is the TML way of adding an adhoc column to the grid. Am  
> assuming
> once I can find this I can delegate rendering to a block defined by my
> mixin's TML.
>
>
>
> Any help appreciated,
>
> Alfie.
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org