You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Dave Greggory <da...@yahoo.com> on 2009/02/06 01:33:55 UTC

[T5] Dynamically getting a component from IoC

Is it possible dynamically (programmatically) request a component from tapestry's IoC (without using @Inject or passing component via parameter)?

I have this MyComponentInterface and a whole bunch of components that implement it (ie. MyComponent1, MyComponent2, etc). I do not know until runtime if any of these components will be rendered or exactly which implementation will be used. On top of that, MyComponent1 may be rendered multiple times (each time with a different configuration) and I do not know the number of times till runtime either. 

So, is it possible to grab a component from IoC at runtime?

Dave



      


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


Re: [T5] Dynamically getting a component from IoC

Posted by Dave Greggory <da...@yahoo.com>.
Nice... thanks, Howard.



----- Original Message ----
From: Howard Lewis Ship <hl...@gmail.com>
To: Tapestry users <us...@tapestry.apache.org>
Sent: Friday, February 6, 2009 2:08:08 PM
Subject: Re: [T5] Dynamically getting a component from IoC

The idea is that you have somewhere in your application a Block that
supplies the components and markup that you need.

You delegate to a method that @Injects the ComponentSource and, using
rules that you devise, obtains a page instance and then obtains a
block from that page instance and returns it.  That block will be
rendered in place of the Delegate component, even though it is on a
different page entirely ... a block acts like a closure on its
containing page.  This is a very powerful concept, the highest order
of Tapestry skill is when you "grok the block".

On Fri, Feb 6, 2009 at 7:07 AM, Dave Greggory <da...@yahoo.com> wrote:
>
> I am using the delegate, but it's getting the "to-component" of delegate that I need to do at runtime. I cannot already have the "to-component" declared with @Inject because I do not know what it is till runtime.
>
>
> ----- Original Message ----
> From: Thiago H. de Paula Figueiredo <th...@gmail.com>
> To: Tapestry users <us...@tapestry.apache.org>
> Sent: Friday, February 6, 2009 5:57:53 AM
> Subject: Re: [T5] Dynamically getting a component from IoC
>
> On Thu, Feb 5, 2009 at 10:33 PM, Dave Greggory <da...@yahoo.com> wrote:
>> Is it possible dynamically (programmatically) request a component from tapestry's IoC (without using @Inject or passing component via parameter)?
>>
>> I have this MyComponentInterface and a whole bunch of components that implement it (ie. MyComponent1, MyComponent2, etc). I do not know until runtime if any of these components will be rendered or exactly which implementation will be used. On top of that, MyComponent1 may be rendered multiple times (each time with a different configuration) and I do not know the number of times till runtime either.
>>
>> So, is it possible to grab a component from IoC at runtime?
>
> AFAIK, no. Components are handled outside Tapestry-IoC. I suggest you
> to use blocks and the Delegate component to accomplish what you want.
> There's a simple example at
> http://tapestry.apache.org/tapestry5/tapestry-core/ref/org/apache/tapestry5/corelib/components/Delegate.html.
>
> --
> 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
>
>



-- 
Howard M. Lewis Ship

Creator Apache Tapestry and Apache HiveMind

---------------------------------------------------------------------
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: [T5] Dynamically getting a component from IoC

Posted by Howard Lewis Ship <hl...@gmail.com>.
The idea is that you have somewhere in your application a Block that
supplies the components and markup that you need.

You delegate to a method that @Injects the ComponentSource and, using
rules that you devise, obtains a page instance and then obtains a
block from that page instance and returns it.  That block will be
rendered in place of the Delegate component, even though it is on a
different page entirely ... a block acts like a closure on its
containing page.  This is a very powerful concept, the highest order
of Tapestry skill is when you "grok the block".

On Fri, Feb 6, 2009 at 7:07 AM, Dave Greggory <da...@yahoo.com> wrote:
>
> I am using the delegate, but it's getting the "to-component" of delegate that I need to do at runtime. I cannot already have the "to-component" declared with @Inject because I do not know what it is till runtime.
>
>
> ----- Original Message ----
> From: Thiago H. de Paula Figueiredo <th...@gmail.com>
> To: Tapestry users <us...@tapestry.apache.org>
> Sent: Friday, February 6, 2009 5:57:53 AM
> Subject: Re: [T5] Dynamically getting a component from IoC
>
> On Thu, Feb 5, 2009 at 10:33 PM, Dave Greggory <da...@yahoo.com> wrote:
>> Is it possible dynamically (programmatically) request a component from tapestry's IoC (without using @Inject or passing component via parameter)?
>>
>> I have this MyComponentInterface and a whole bunch of components that implement it (ie. MyComponent1, MyComponent2, etc). I do not know until runtime if any of these components will be rendered or exactly which implementation will be used. On top of that, MyComponent1 may be rendered multiple times (each time with a different configuration) and I do not know the number of times till runtime either.
>>
>> So, is it possible to grab a component from IoC at runtime?
>
> AFAIK, no. Components are handled outside Tapestry-IoC. I suggest you
> to use blocks and the Delegate component to accomplish what you want.
> There's a simple example at
> http://tapestry.apache.org/tapestry5/tapestry-core/ref/org/apache/tapestry5/corelib/components/Delegate.html.
>
> --
> 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
>
>



-- 
Howard M. Lewis Ship

Creator Apache Tapestry and Apache HiveMind

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


Re: [T5] Dynamically getting a component from IoC

Posted by Dave Greggory <da...@yahoo.com>.
I am using the delegate, but it's getting the "to-component" of delegate that I need to do at runtime. I cannot already have the "to-component" declared with @Inject because I do not know what it is till runtime.


----- Original Message ----
From: Thiago H. de Paula Figueiredo <th...@gmail.com>
To: Tapestry users <us...@tapestry.apache.org>
Sent: Friday, February 6, 2009 5:57:53 AM
Subject: Re: [T5] Dynamically getting a component from IoC

On Thu, Feb 5, 2009 at 10:33 PM, Dave Greggory <da...@yahoo.com> wrote:
> Is it possible dynamically (programmatically) request a component from tapestry's IoC (without using @Inject or passing component via parameter)?
>
> I have this MyComponentInterface and a whole bunch of components that implement it (ie. MyComponent1, MyComponent2, etc). I do not know until runtime if any of these components will be rendered or exactly which implementation will be used. On top of that, MyComponent1 may be rendered multiple times (each time with a different configuration) and I do not know the number of times till runtime either.
>
> So, is it possible to grab a component from IoC at runtime?

AFAIK, no. Components are handled outside Tapestry-IoC. I suggest you
to use blocks and the Delegate component to accomplish what you want.
There's a simple example at
http://tapestry.apache.org/tapestry5/tapestry-core/ref/org/apache/tapestry5/corelib/components/Delegate.html.

-- 
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: [T5] Dynamically getting a component from IoC

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Thu, Feb 5, 2009 at 10:33 PM, Dave Greggory <da...@yahoo.com> wrote:
> Is it possible dynamically (programmatically) request a component from tapestry's IoC (without using @Inject or passing component via parameter)?
>
> I have this MyComponentInterface and a whole bunch of components that implement it (ie. MyComponent1, MyComponent2, etc). I do not know until runtime if any of these components will be rendered or exactly which implementation will be used. On top of that, MyComponent1 may be rendered multiple times (each time with a different configuration) and I do not know the number of times till runtime either.
>
> So, is it possible to grab a component from IoC at runtime?

AFAIK, no. Components are handled outside Tapestry-IoC. I suggest you
to use blocks and the Delegate component to accomplish what you want.
There's a simple example at
http://tapestry.apache.org/tapestry5/tapestry-core/ref/org/apache/tapestry5/corelib/components/Delegate.html.

-- 
Thiago

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