You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Lance Java <la...@googlemail.com> on 2012/11/07 09:33:22 UTC

Can I attach an instance mixin to a nested component

The grid component contains a nested "rows" component of type GridRows. Is
there a way that I can attach a mixin to the nested GridRows instance? I
realise that this can be done globally via a ComponentTransformWorker2 but
I'd like to apply an instance mixin.

FYI, here's the code that initialises rows:

public class Grid {
    ...
    @Component(parameters =
    { "columnIndex=inherit:columnIndex", "rowsPerPage=rowsPerPage",
"currentPage=currentPage", "row=row",
            "overrides=overrides" }, publishParameters =
"rowIndex,rowClass,volatile,encoder,lean")
    private GridRows rows;
    ...
}



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Can-I-attach-an-instance-mixin-to-a-nested-component-tp5717741.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Can I attach an instance mixin to a nested component

Posted by Lance Java <la...@googlemail.com>.
> it seems easier to install both mixins with a component transformer and
then just have a parameter on the grid control the row

I disagree, mixins are a well understood concept. Asking a user of my
library to add a mixin to a grid and then pass parameters to that mixin is
well documented. Using class transformations and then telling the user to
add some random informal parameter to the grid is a bit too magic for my
liking.




--
View this message in context: http://tapestry.1045711.n5.nabble.com/Can-I-attach-an-instance-mixin-to-a-nested-component-tp5717741p5717810.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Can I attach an instance mixin to a nested component

Posted by trsvax <tr...@gmail.com>.
I guess you could implement it that way but it seems easier to install both
mixins with a component transformer and then just have a parameter on the
grid control the row rather than the existence of the grid mixin



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Can-I-attach-an-instance-mixin-to-a-nested-component-tp5717741p5717791.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Can I attach an instance mixin to a nested component

Posted by Lance Java <la...@googlemail.com>.
A stack works fine when every grid is guaranteed to put a value on the stack.
Since the mixin is optional, the environmental is also optional. So a nested
Grid might see an environmental from a parent Grid when the value should
have been null.



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Can-I-attach-an-instance-mixin-to-a-nested-component-tp5717741p5717786.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Can I attach an instance mixin to a nested component

Posted by trsvax <tr...@gmail.com>.
I don't think nested grids would be a problem because environment variables
are a stack



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Can-I-attach-an-instance-mixin-to-a-nested-component-tp5717741p5717785.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Can I attach an instance mixin to a nested component

Posted by Lance Java <la...@googlemail.com>.
> Why not the Environment for passing parameters?
Since all nested components will be able to see the environmental, you might
get unexpected behavior for a grid inside a grid. 



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Can-I-attach-an-instance-mixin-to-a-nested-component-tp5717741p5717780.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Can I attach an instance mixin to a nested component

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Wed, 07 Nov 2012 12:41:48 -0200, Lance Java <la...@googlemail.com>  
wrote:

> I think I've got a solution:
> 1. GridMixin calls ComponentResources.storeRenderVariable(name, value) to
> make config available to GridRowsMixin
> 2. GridRowsMixin calls
> ComponentResources.getContainerResources().getRenderVariable(name)
> 3. ComponentResources.getComponentModel().getMixinClassNames() is also
> available if need be
>
> So, is ComponentResources.storeRenderVariable(...) likely to be  
> deprecated? I remember HLS cussing about it a while ago.

Why not the Environment for passing parameters?

-- 
Thiago H. de Paula Figueiredo

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


Re: Can I attach an instance mixin to a nested component

Posted by Lance Java <la...@googlemail.com>.
I think I've got a solution:
1. GridMixin calls ComponentResources.storeRenderVariable(name, value) to
make config available to GridRowsMixin
2. GridRowsMixin calls
ComponentResources.getContainerResources().getRenderVariable(name)
3. ComponentResources.getComponentModel().getMixinClassNames() is also
available if need be

So, is ComponentResources.storeRenderVariable(...) likely to be deprecated?
I remember HLS cussing about it a while ago.



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Can-I-attach-an-instance-mixin-to-a-nested-component-tp5717741p5717766.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Can I attach an instance mixin to a nested component

Posted by trsvax <tr...@gmail.com>.
I would try using an informal parameter on the grid instead of a Mixin. The
row mixin should be able to access that with

ComponentResources.getInformalParameter(String name, Class<T> type) 

so in your template

<t:gird rowMixinParam="mixinValue" .../>



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Can-I-attach-an-instance-mixin-to-a-nested-component-tp5717741p5717764.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Can I attach an instance mixin to a nested component

Posted by Lance Java <la...@googlemail.com>.
Ok, so rolling with your suggestion...

Let's assume that I use a CTW2 to attach a GridRowsMixin to every GridRows
component. And now, I attach a GridMixin to the Grid. Is there any way that
the GridRowsMixin can lookup the GridMixin? To rephrase my question, can a
mixin on a child component lookup the mixins attached to it's parent? I
can't find anything on ComponentResources.

Using a GridMixin would be my preferred way to trigger the GridRowsMixin to
fire (and pass any parameters). I'd prefer not to use an Environmental to
communicate with the GridRowsMixin.




--
View this message in context: http://tapestry.1045711.n5.nabble.com/Can-I-attach-an-instance-mixin-to-a-nested-component-tp5717741p5717763.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Can I attach an instance mixin to a nested component

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Wed, 07 Nov 2012 06:33:22 -0200, Lance Java <la...@googlemail.com>  
wrote:

> The grid component contains a nested "rows" component of type GridRows.  
> Is there a way that I can attach a mixin to the nested GridRows instance?

I don't think so.

> I realise that this can be done globally via a ComponentTransformWorker2  
> but I'd like to apply an instance mixin.

You can applyl an instance mixin in a non-global way in a  
ComponentTransformWorker2: you just need use some logic to apply it or not  
to a given component instance.

-- 
Thiago H. de Paula Figueiredo

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


Re: Can I attach an instance mixin to a nested component

Posted by Kalle Korhonen <ka...@gmail.com>.
On Wed, Nov 7, 2012 at 8:52 AM, Lance Java <la...@googlemail.com>wrote:

> > Lance, you might be interested in
> https://issues.apache.org/jira/browse/TAP5-1606.
> Interesting, I think the @EmbeddedMixin functionality is cleaner than what
> I
> suggested. I do agree with HLS' comment on the issue that it breaks the
> black box philosophy of components. But given the alternatives, I think
> it's
> also the cleanest option.
>

Exactly how I see it. It would pretty cool if you could, in a generic
manner, attach a context menu to a grid cell of any grid with a mixin. We'd
need to open up the lid just a bit to peek inside of the black box to see
the nested components inside but the alternative is implementing your own
version of the same components. Targeting types of nested components seems
like a reasonable compromise between a strict philosophy and free-for-all
flexibility.

Kalle

Re: Can I attach an instance mixin to a nested component

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Wed, 07 Nov 2012 14:52:42 -0200, Lance Java <la...@googlemail.com>  
wrote:

>> Lance, you might be interested in
> https://issues.apache.org/jira/browse/TAP5-1606.
>
> Interesting, I think the @EmbeddedMixin functionality is cleaner than  
> what I
> suggested. I do agree with HLS' comment on the issue that it breaks the
> black box philosophy of components. But given the alternatives, I think  
> it's also the cleanest option.

I haven't tried, but I still think you can implement what you want just  
using component transformations.

-- 
Thiago H. de Paula Figueiredo

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


Re: Can I attach an instance mixin to a nested component

Posted by Lance Java <la...@googlemail.com>.
> Lance, you might be interested in
https://issues.apache.org/jira/browse/TAP5-1606.

Interesting, I think the @EmbeddedMixin functionality is cleaner than what I
suggested. I do agree with HLS' comment on the issue that it breaks the
black box philosophy of components. But given the alternatives, I think it's
also the cleanest option.



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Can-I-attach-an-instance-mixin-to-a-nested-component-tp5717741p5717784.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Can I attach an instance mixin to a nested component

Posted by Kalle Korhonen <ka...@gmail.com>.
On Wed, Nov 7, 2012 at 8:13 AM, Lance Java <la...@googlemail.com>wrote:

> > I've overwritten both the Grid class and the GridRows class to make it
> happen
> Sounds like this might be a problem that needs addressing then... perhaps
> there should be a mechanism in tapestry to add mixins to subcomponents?
>

Lance, you might be interested in
https://issues.apache.org/jira/browse/TAP5-1606. Vote?

Kalle



>
> eg:
> <t:grid source="..." mixins="gridMixin" submixins="prop:subMixins" .../>
>
> public Map<String,String> getSubMixins() {
>    Map map = new HashMap();
>    map.put("rows", "rowsMixins1,rowsMixin2");
>    map.put("pager", "pagerMixin");
>    map.put("columns", "columnsMixin1,columnsMixin2");
>    return map;
> }
>
>
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/Can-I-attach-an-instance-mixin-to-a-nested-component-tp5717741p5717781.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Can I attach an instance mixin to a nested component

Posted by Lance Java <la...@googlemail.com>.
> I've overwritten both the Grid class and the GridRows class to make it
happen
Sounds like this might be a problem that needs addressing then... perhaps
there should be a mechanism in tapestry to add mixins to subcomponents?

eg:
<t:grid source="..." mixins="gridMixin" submixins="prop:subMixins" .../>

public Map<String,String> getSubMixins() {
   Map map = new HashMap();
   map.put("rows", "rowsMixins1,rowsMixin2");
   map.put("pager", "pagerMixin");
   map.put("columns", "columnsMixin1,columnsMixin2");
   return map;
}



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Can-I-attach-an-instance-mixin-to-a-nested-component-tp5717741p5717781.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Can I attach an instance mixin to a nested component

Posted by Lance Java <la...@googlemail.com>.
I was able to solve my problem by developing a GridDecorator mixin which
applies RowDecorators and CellDecorators.

Code Here:
https://github.com/uklance/tapestry-stitch/blob/master/src/main/java/org/lazan/t5/stitch/mixins/GridDecorator.java
https://github.com/uklance/tapestry-stitch/blob/master/src/main/java/org/lazan/t5/stitch/model/CellDecorator.java
https://github.com/uklance/tapestry-stitch/blob/master/src/main/java/org/lazan/t5/stitch/model/RowDecorator.java

Demo Here:
https://github.com/uklance/tapestry-stitch-demo/blob/master/src/main/java/org/lazan/t5/stitch/demo/pages/GridDecoratorDemo.java
https://github.com/uklance/tapestry-stitch-demo/blob/master/src/main/resources/org/lazan/t5/stitch/demo/pages/GridDecoratorDemo.tml

Cheers,
Lance.



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Can-I-attach-an-instance-mixin-to-a-nested-component-tp5717741p5717914.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Can I attach an instance mixin to a nested component

Posted by antalk <na...@vankalleveen.net>.
Yes you can,

However ( in my case) i've overwritten both the Grid class and the GridRows
class to make it happen and use chennillekit's onEvent mixin:

Grid.class:   ( not everything)

@Mixins("ck/OnEvent")
	@Component(parameters = { 
			"columnIndex=inherit:columnIndex", 
			"rowsPerPage=rowsPerPage", 
			"currentPage=currentPage", 
			"row=row",
			"overrides=overrides",
	        "event=literal:click",
	        "onCompleteCallback=clickRow"
	        }, 
	        publishParameters = "rowIndex,rowClass,volatile,encoder,lean")
	private yourcompany.components.GridRows rows;


And i did some changes to the gridrows class to give me a unique ID
identifying the current row.




--
View this message in context: http://tapestry.1045711.n5.nabble.com/Can-I-attach-an-instance-mixin-to-a-nested-component-tp5717741p5717777.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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