Thanks James, that looks very good, I will look into it.
James Carman wrote:
This is a little verbose, but here's what I would do:
1. Define the following three classes:
public interface BlockRepository
{
public Block getBlock( String name );
}
public class BlockRepositoryImpl implements BlockRepository
{
private IRequestCycle requestCycle;
private Map<String, ComponentAddress> blockAddressMap;
public Block getBlock( String name )
{
final ComponentAddress componentAddress = blockAddressMap.get( name
);
return ( Block )( componentAddress == null ? null :
componentAddress.findComponent( requestCycle ) );
}
public void setRequestCycle( IRequestCycle requestCycle )
{
this.requestCycle = requestCycle;
}
public void setBlockAddressMap( Map<String,ComponentAddress>
blockAddressMap )
{
this.blockAddressMap = new HashMap<String,ComponentAddress>(
blockAddressMap );
}
}
public class BlockAddressRule extends BaseLocatable implements Rule
{
public void begin( SchemaProcessor schemaProcessor, Element element )
{
schemaProcessor.addElement( new ComponentAddress(
element.getAttributeValue( "pageName" ),
element.getAttributeValue( "idPath" ) ) );
}
public void end( SchemaProcessor schemaProcessor, Element element )
{
}
}
2. Define a service point in HiveMind:
<service-point id="BlockRepository"
interface="com.myco.web.service.BlockRepository">
<invoke-factory>
<construct
class="com.myco.web.service.impl.BlockRepositoryImpl">
<set-configuration property="blockAddressMap"
configuration-id="BlockAddresses" />
</construct>
</invoke-factory>
</service-point>
3. Define a configuration point which holds the blocks:
<configuration-point id="BlockAddresses">
<schema>
<element name="block" key-attribute="name">
<attribute name="name" unique="true" required="true" />
<attribute name="pageName" required="true" />
<attribute name="idPath" required="true" />
<rules>
<custom
class="com.myco.web.service.impl.BlockAddressRule" />
</rules>
</element>
</schema>
</configuration-point>
4. Define a page to hold your blocks:
PageName = DynamicComponents.html
<span jwcid="[EMAIL PROTECTED]">
This is a block that came from the repository!
</span>
5. Register your block(s) with the repository:
<contribution configuration-id="BlockAddresses">
<block name="test" pageName="DynamicComponents" idPath="testBlock"
/>
</contribution>
6. Define a helper method in your page class:
@InjectObject( "service:mymodule.BlockRepository" )
public abstract BlockRepository getBlockRepository();
public Block getBlock( String name )
{
return getBlockRepository().getBlock( name );
}
7. Use the block in your page:
<span jwcid="@RenderBlock" block="ognl:getBlock('test')" />
-----Original Message-----
From: Mark Stang [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 02, 2006 11:13 AM
To: Tapestry users; tapestry-user@jakarta.apache.org
Subject: RE: Re: Dynamic pages
Sounds like portlets...
-----Original Message-----
From: news on behalf of Raul Raja Martinez
Sent: Thu 3/2/2006 5:32 AM
To: tapestry-user@jakarta.apache.org
Subject: Re: Dynamic pages
You should also know that it is not possible to add components
dynamically at runtime. There have been many discussions about this in
this list. I'm trying to build a CMS in Tapestry and I having a hard
time with this too.
I would like to provide the functionality for people to write their own
modules that can be dropped in the CMS and dinamically position on
different places and different pages, but because of the static
structure of Tapestry Components, I'm still not sure how to approach that.
Any help is appreciated.
James Carman wrote:
Typically, if you want to add a dynamic number of components or the type
of
component is based on some data and you're not talking about the @If and
@For situations, you use @Blocks for that. In Trails, we have "editor
blocks" defined on another page. Then, based on the property type, we
choose which block to display (show the checkboxEditor for boolean
properties).
-----Original Message-----
From: Rudolf Baloun [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 02, 2006 5:22 AM
To: Tapestry users
Subject: Re: Dynamic pages
Hi Peter,
here is the easiest solution:
http://jakarta.apache.org/tapestry/tapestry/ComponentReference/If.html
put in your page something like this:
<span jwcid="@If" condition="ognl:theCondition">
....
</span>
Now you got to implement the "isTheConditon()" in your java-code (in the
Page).
Dynamic number of components:
http://jakarta.apache.org/tapestry/tapestry/ComponentReference/For.html
I dont know if it is what you want to know.
Look in the componentreference.....
Rudolf B.
Peter Verhoye wrote:
Hi all,
It happens sometimes that I'm starting to think of new interesting
projects to create myself. Since I've recently discovered Tapestry, I
wanted to do something with it. However, I have a problem for which I
haven't found a solution yet.
Let's say you have a page on which you want to display a non-predefined
number of components and that the location for them on that page is not
defined also.
I guess the later you could do by somehow changing the css style of the
page at runtime.
But how would you do the former? Is it possible to dynamically add
components to a page?
Any help or discussion would be greatly appreciated :-)
BB
Peter
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]