You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Erich Gormann <e....@gormann.de> on 2015/02/13 18:51:30 UTC

How to get container inside self written component

Hi all,

seems to be a simple task, but I did not manage it right now.
I'm working with a self written component. Inside the code of this 
component I want to retrieve information about the outer component 
(container), my component is currently used in.

I tried the service ComponentSource, but I'm only was able to get the 
root component via getActivePage(). Thats not want I want. I need 
information about the direct container of my component, because it's 
required to do some reflection tasks on it.

Do you have some hints for me? Thanks a lot in advance.

Greetings, Eric


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


Re: AW: How to get container inside self written component

Posted by Lance Java <la...@googlemail.com>.
In my opinion, @InjectContainer is a bit fragile. I think you're much
better off using the Environment or a component parameter. Let's consider a
future case where you want to render the child component in a loop (or
maybe an 'if' component). In this case the parent will be the loop/if and
it won't work without refactoring.
On 13 Feb 2015 19:11, "Thiago H de Paula Figueiredo" <th...@gmail.com>
wrote:

> On Fri, 13 Feb 2015 16:44:52 -0200, Poggenpohl, Daniel <
> Daniel.Poggenpohl@isst.fraunhofer.de> wrote:
>
>  Hello,
>> why don't you try @InjectContainer? Or give the necessary information via
>> parameters to the inner component?
>>
>
> Yep, an @InjectContainer private Object parentComponent; field will give
> you the parent component. You can change the field type and name, of
> course. :)
>
> I agree 200% with Daniel: you should avoid manipulating the parent
> component directly as much as possible, as you're coupling one component to
> another, making the inner one just working when used inside a given other
> component.
>
> You can pass information through parameters (recommended) or the
> Environment service (when parameters aren't enough).
>
> Cheers!
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: AW: How to get container inside self written component

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Fri, 13 Feb 2015 16:44:52 -0200, Poggenpohl, Daniel  
<Da...@isst.fraunhofer.de> wrote:

> Hello,
> why don't you try @InjectContainer? Or give the necessary information  
> via parameters to the inner component?

Yep, an @InjectContainer private Object parentComponent; field will give  
you the parent component. You can change the field type and name, of  
course. :)

I agree 200% with Daniel: you should avoid manipulating the parent  
component directly as much as possible, as you're coupling one component  
to another, making the inner one just working when used inside a given  
other component.

You can pass information through parameters (recommended) or the  
Environment service (when parameters aren't enough).

Cheers!

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

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


Re: How to get container inside self written component

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Fri, 13 Feb 2015 17:26:25 -0200, Erich Gormann <e....@gormann.de>  
wrote:

> Hi Thiago,

Hi!

> I see what you mean, but I did not want to manipulate the container  
> component, but only wanted to look up if a certain (self written)  
> annotation is present on it and then let the embedded component to do  
> certain things.
>
> According to my opinion that would be a nice way to get information  
> about the container component without knowing it in the embedded  
> component and without make the unnecessary work for other developers to  
> write one more parameter besides all other ones.
>
> I can not see why an additional parameter is the recommended way here.

Now that you've given the whole picture, specially the annotation part,  
now it makes sense to use @InjectContainer. But remember that  
annotation-level classes are *not* live-reloaded, so, once you put or  
remove the annotation, this check won't work. It can be made to work  
indirectly, implementing and contributing a ComponentClassTransformWorker  
that calls setMeta("someKeyYou'llCreate", "true") in the component's  
ComponentModel when it has the annotation. To query that in the inner  
ocmponent, you can @Inject ComponentResources and use the  
getContainer().getComponentModel().getMeta(String key).

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

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


Re: How to get container inside self written component

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
One last comment: you mentioned self-written component. For Tapestry,  
there's absolutely no distinction at all at the components provided  
out-of-the-box and the components you write. All components, regardless of  
origin, are treated and work the same.

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

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


Re: How to get container inside self written component

Posted by Erich Gormann <e....@gormann.de>.
Hi Thiago,

I see what you mean, but I did not want to manipulate the container 
component, but only wanted to look up if a certain (self written) 
annotation is present on it and then let the embedded component to do 
certain things.

According to my opinion that would be a nice way to get information 
about the container component without knowing it in the embedded 
component and without make the unnecessary work for other developers to 
write one more parameter besides all other ones.

I can not see why an additional parameter is the recommended way here.

Greetings, Eric

Am 13.02.2015 20:11, schrieb Thiago H de Paula Figueiredo:
> On Fri, 13 Feb 2015 17:01:06 -0200, Erich Gormann 
> <e....@gormann.de> wrote:
>
>> Hello Daniel,
>>
>> I wanted to avoid an additional parameter, because there are already 
>> some parameters and if there would another way to manage it, this 
>> would be better.
>
> You're much better off with another parameter then accessing the 
> parent component directly.
>


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


Re: How to get container inside self written component

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Fri, 13 Feb 2015 17:01:06 -0200, Erich Gormann <e....@gormann.de>  
wrote:

> Hello Daniel,
>
> I wanted to avoid an additional parameter, because there are already  
> some parameters and if there would another way to manage it, this would  
> be better.

You're much better off with another parameter then accessing the parent  
component directly.

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

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


Re: How to get container inside self written component

Posted by Erich Gormann <e....@gormann.de>.
Hello Daniel,

I wanted to avoid an additional parameter, because there are already 
some parameters and if there would another way to manage it, this would 
be better.
I'll try the service you proposed, thanks for your answer!

Greetings, Eric


Am 13.02.2015 19:44, schrieb Poggenpohl, Daniel:
> Hello,
> why don't you try @InjectContainer? Or give the necessary information via parameters to the inner component?
>
> Regards,
> Daniel Poggenpohl
> ________________________________________
> Von: Erich Gormann [e.gormann@gormann.de]
> Gesendet: Freitag, 13. Februar 2015 18:51
> An: Tapestry users
> Betreff: How to get container inside self written component
>
> Hi all,
>
> seems to be a simple task, but I did not manage it right now.
> I'm working with a self written component. Inside the code of this
> component I want to retrieve information about the outer component
> (container), my component is currently used in.
>
> I tried the service ComponentSource, but I'm only was able to get the
> root component via getActivePage(). Thats not want I want. I need
> information about the direct container of my component, because it's
> required to do some reflection tasks on it.
>
> Do you have some hints for me? Thanks a lot in advance.
>
> Greetings, Eric
>
>
> ---------------------------------------------------------------------
> 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
>
>
>


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


AW: How to get container inside self written component

Posted by "Poggenpohl, Daniel" <Da...@isst.fraunhofer.de>.
Hello,
why don't you try @InjectContainer? Or give the necessary information via parameters to the inner component?

Regards,
Daniel Poggenpohl
________________________________________
Von: Erich Gormann [e.gormann@gormann.de]
Gesendet: Freitag, 13. Februar 2015 18:51
An: Tapestry users
Betreff: How to get container inside self written component

Hi all,

seems to be a simple task, but I did not manage it right now.
I'm working with a self written component. Inside the code of this
component I want to retrieve information about the outer component
(container), my component is currently used in.

I tried the service ComponentSource, but I'm only was able to get the
root component via getActivePage(). Thats not want I want. I need
information about the direct container of my component, because it's
required to do some reflection tasks on it.

Do you have some hints for me? Thanks a lot in advance.

Greetings, Eric


---------------------------------------------------------------------
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