You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Inge Solvoll <in...@gmail.com> on 2010/06/19 12:14:19 UTC

T5: Using the strategy pattern with components.

Hi!

I'm trying to migrate our company's software over to a more plugin oriented
architecture.

So far I've come up with some services that utilize the Strategy pattern to
produce information about different modules in our system, without the core
module knowing anything about their implementation. Detail modules push info
to the core module by contributing to my strategy service.

My next challenge is to aquire components the same way. More specifically, I
want some core application page /component/service to lookup the correct
component/block for displaying information about a specific module that it
doesn't know. I would like to do this using the same pattern (strategy).

I think I've seen people on the list talking about creating pages with
blocks in them, and then access these blocks from the core page. If this is
true, does anyone have code samples on how to inject, activate and render
other pages and move some specific block into the current page?

Am I making sense or do you need more/better details?

Inge

Re: T5: Using the strategy pattern with components.

Posted by jochenfrey <jo...@jochenfrey.com>.
Is there a way to get a reference to a component (or block) by classname
(MyComponent.class), instead of the id?  I tried out the approach Thiago
suggested, and it works fine.  However, it requires me to keep a page with a
catalog of components around (not the end of the world, but inconvenient).

Any suggestions?

Thanks!


PS: Here's code for the approach Thiago suggested:

Container.java:
    public Object getTheComponent ()    {
        org.apache.tapestry5.runtime.Component component =
componentSource.getComponent("Catalog:component1");
        return component;
    }

Container.tml:
<html t:sidebarTitle="Framework Version"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd" >
    <t:delegate to="theComponent"/>
</html>

Catalog.tml:
<t:block>
    <t:component1 t:id="component1"/>
</t:block>


--
View this message in context: http://tapestry.1045711.n5.nabble.com/T5-Using-the-strategy-pattern-with-components-tp2411126p5124735.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: T5: Using the strategy pattern with components.

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Sat, 19 Jun 2010 19:09:47 -0300, Inge Solvoll <in...@gmail.com>  
wrote:

> Thanks!

You're welcome!

> Don't see how ComponentSource helps, how does it get me to the point  
> where I can retrieve a named block from a page/component?

Description in Slashdot style*:

1) Use ComponentSource.getPage(). It will return a page instance as a  
Component object (in Tapestry 5, pages *are* components).
2) Then use Component.getComponentResources().findBlock(String blockId) to  
get the block.
3) Use the Delegate component to render it. Alternatively, you can render  
the Block by returning it in a method that handles a component rendering  
event.
4) ????
5) Profit! :P

* I just discovered that this meme has its origins at a South Park episode.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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


Re: T5: Using the strategy pattern with components.

Posted by Inge Solvoll <in...@gmail.com>.
Thanks!

Don't see how ComponentSource helps, how does it get me to the point where I
can retrieve a named block from a page/component?

On Sat, Jun 19, 2010 at 7:43 PM, Thiago H. de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> On Sat, 19 Jun 2010 13:52:04 -0300, Inge Solvoll <in...@gmail.com>
> wrote:
>
>  Been doing a lot of searching today to find leads, and I think I got
>> something in BeanBlockOverrideSourceImpl.
>>
>
> That's where I learned how the BeanEditor/BeanEditSource blocks work. :)
>
>
>  Using PageRequestCache and page.getRootElement().getBlock(blockId) seems
>> to be a promising lead. This way I can have a Strategy service that returns
>> the page name that contains display blocks for the given entity object.
>>
>
> You're on the right path . . .
>
>
>  I feel like I'm digging quite deep into the inner mechanics of Tapestry
>> (PageRequestCache is an internal service), but I guess there is no way to
>> avoid that with such advanced requirements?
>>
>
> Use ComponentSource instead. It uses PageRequestCache internally (can't
> remember if directly or indirectly).
>
> --
> Thiago H. de Paula Figueiredo
> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
> and instructor
> Owner, Ars Machina Tecnologia da Informação Ltda.
> http://www.arsmachina.com.br
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: T5: Using the strategy pattern with components.

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Sat, 19 Jun 2010 13:52:04 -0300, Inge Solvoll <in...@gmail.com>  
wrote:

> Been doing a lot of searching today to find leads, and I think I got
> something in BeanBlockOverrideSourceImpl.

That's where I learned how the BeanEditor/BeanEditSource blocks work. :)

> Using PageRequestCache and page.getRootElement().getBlock(blockId) seems  
> to be a promising lead. This way I can have a Strategy service that  
> returns the page name that contains display blocks for the given entity  
> object.

You're on the right path . . .

> I feel like I'm digging quite deep into the inner mechanics of Tapestry
> (PageRequestCache is an internal service), but I guess there is no way to
> avoid that with such advanced requirements?

Use ComponentSource instead. It uses PageRequestCache internally (can't  
remember if directly or indirectly).

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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


Re: T5: Using the strategy pattern with components.

Posted by Inge Solvoll <in...@gmail.com>.
Been doing a lot of searching today to find leads, and I think I got
something in BeanBlockOverrideSourceImpl.

Using PageRequestCache and page.getRootElement().getBlock(blockId) seems to
be a promising lead. This way I can have a Strategy service that returns the
page name that contains display blocks for the given entity object.

I feel like I'm digging quite deep into the inner mechanics of Tapestry
(PageRequestCache is an internal service), but I guess there is no way to
avoid that with such advanced requirements?


On Sat, Jun 19, 2010 at 12:14 PM, Inge Solvoll <in...@gmail.com>wrote:

> Hi!
>
> I'm trying to migrate our company's software over to a more plugin oriented
> architecture.
>
> So far I've come up with some services that utilize the Strategy pattern to
> produce information about different modules in our system, without the core
> module knowing anything about their implementation. Detail modules push info
> to the core module by contributing to my strategy service.
>
> My next challenge is to aquire components the same way. More specifically,
> I want some core application page /component/service to lookup the correct
> component/block for displaying information about a specific module that it
> doesn't know. I would like to do this using the same pattern (strategy).
>
> I think I've seen people on the list talking about creating pages with
> blocks in them, and then access these blocks from the core page. If this is
> true, does anyone have code samples on how to inject, activate and render
> other pages and move some specific block into the current page?
>
> Am I making sense or do you need more/better details?
>
> Inge
>