I didn't get an answer to this so I'll try rewording it and see if that
helps! Thanks in advance!

The order of Blocks on my pages is to be configurable. So as to have
clean HTML mock-ups for clients to see, the Blocks are moved into
another page. For ease of maintenance, I would like to create a new
component for each Block. If I do not create a component for each Block,
it renders fine, but this means that my page referencing the individual
Blocks is a whole load of mark-up which I feel should be put into
separate components.

The .html template that actually renders the Blocks:
...
<span jwcid="forEachBlock">
        <span jwcid="renderBlock"/>
</span>
...

Corresponding .page:
...
<component id="forEachBlock" type="For">
        <binding name="source" value="ognl:pageLayout"/>
        <binding name="value" value="ognl:currentPageComponent"/>
        <binding name="index" value="ognl:componentIndex"/>
</component>

<component id="renderBlock" type="RenderBlock">
        <binding name="block" value="ognl:currentBlock"/>
</component>
...

And the .java:
...
public Block getCurrentBlock() {
        Block block = null;
        IRequestCycle cycle = getRequestCycle();
        switch (getComponentIndex()) {
        case 0:
                block = (Block)
cycle.getPage("BlocksTemplate").getComponent("firstBlock");
                break;
        default:
        block = (Block)
cycle.getPage("BlocksTemplate").getComponent("secondBlock");
                break;
        }
        return block;
}
...

Now BlocksTemplate.html:
<span jwcid="firstBlock"/>
<span jwcid="secondBlock"/>

And BlocksTemplate.page:
...
<component id="firstBlock" type="Block1"/>
<component id="secondBlock" type="Block2"/>
...

Block1.html (and Block2.html identical at the moment):
<div style="border:1px solid #000000;">
        <img jwcid="genImage"/><br/>
        <span jwcid="insertString"/>
</div>

Block1.jwc:
<component-specification class=" TestBlock">
<component id="genImage" type="jim:GeneratedImage">
        <binding name="backgroundImagePath"
value="literal:/images/background.png"/>
        <binding name="stringToWrite"
value="ognl:currentPageComponent.title"/>
        <binding name="fontFilePath"
value="literal:/images/HATTEN.TTF"/>
        <binding name="fontSize" value="literal:80"/>
        <binding name="fontColour" value="literal:#ffffff"/>
        <binding name="outputDir" value="literal:/images/"/>
        <binding name="imageFormat" value="literal:png"/>
</component>
        
<component id="insertString" type="Insert">
        <binding name="value"
value="ognl:currentPageComponent.stringFromBlock1"/>
</component>
</component-specification>

TestBlock.java:
public class TestBlock extends Block {
        public PageComponent getCurrentPageComponent() {
                return new PageComponent("Hello", "Goodbye",
"Something");
        }
}

As I said above if this is contained in the BlocksTemplate page then all
works fine - just when it is being pulled out into separate components.

-----Original Message-----
From: Jimmi Dyson [mailto:[EMAIL PROTECTED] 
Sent: 20 December 2005 11:12
To: 'Tapestry users'
Subject: Rendering block from other page

I have to select which block to render depending upon database
configuration. To keep clean HTML mock-ups, I have moved the blocks into
a separate page. The blocks are specified as separate components,
subclassing Block.

My problem is that they don't get rendered at all and I'm not sure why.

Home.html:
...
<span jwcid="forEachModule">
        <div style="border: 1px" jwcid="blockDiv">
                <span jwcid="renderBlock"/>
        </div>
</span>
...

Home.page:
...
<component id="renderBlock" type="RenderBlock">
        <binding name="block" value="ognl: currentBlock"/>
        <binding name="featureModule" value="ognl: currentModule"/>
</component>
...

Using featureModule as an informal parameter to pass to the rendering
block, retrieved through getParameter("featureModule") in block class.

HomePage.java:
...
public Block getCurrentBlock() {
        IPage blocksPage = getCycle().getPage("Blocks");
        Block block = (Block) blocksPage.getComponent("fullWidthBlock");
        return block;
}
...

Blocks.page:
...
<component id="fullWidthBlock" type="FullWidthBlock"/>
...

FullWidthBlock never gets rendered. If fullWidthBlock is just static
HTML contained in Blocks.html rather than FullWidthBlock.html, it gets
rendered fine, but I would rather not have to have all HTML for each
block I have to render in Blocks.html.  In fact that wouldn't be
possible as I have to pass a parameter to the Block to render
(featureModule informal parameter above).

Have I missed something or is this just not possible at the moment?

Thanks for your help,
Jim Dyson



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

Reply via email to