You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Karthik N <ka...@gmail.com> on 2006/11/07 05:22:01 UTC

Question regarding Block/RenderBlock

Hello,

"RenderBlock does not mandate that the Block being rendered be contained
within the page being rendered"

I have seen this statement at so many places - but I am looking for an
example/explanation of how to do it.

Any pointers?

Thanks, Karthik

RE: Question regarding Block/RenderBlock

Posted by Firas Adiler <ta...@idigna.com>.
Ohh, I see...

If we take Navin's example and assume that your blocks are in MyBlocks page:
<span jwcid="block1@Block"><span jwcid="@Insert"
value="ognl:testValue"/></span>

then the 'testValue' property will be called on MyBlocks,
MyBlocks.getTestValue().

The only interaction, that I'm aware of, between MyBlocks and other pages is
like this:
 
<!-- somwhere not in MyBlocks -->
<del wcid="Caller@RenderBlock" block="ognl:MyBlocks.components.block1"
param1="prop:testString" />
 
Note the use of an informal parameter 'param1'.

In MyBlocks page you can access this informal parameter like this:
 
Block theBlock = (Block) getComponent("block1");
IComponent invoker = theBlock.getInvoker(); // Will point to
Caller@RenderBlock
String parameter1 = (String) invoker.getBinding("param1").getObject();
 
 
Regards,
 
</Firas>
 

-----Original Message-----
From: Karthik N [ <ma...@gmail.com>
mailto:karthik.nar@gmail.com]
Sent: Thursday, November 09, 2006 3:40 PM
To: Tapestry users
Subject: Re: Question regarding Block/RenderBlock

Hi Navin,

You are right.  That is exactly my doubt/question.  How do OGNL bindings
work for nested components inside a Block that is a part of a different page
and NOT the page that is currently being rendered.

Thanks, Karthik

On 11/9/06, B.S.Navin <bs...@effigent.net> wrote:
>
> Hi Firas,
>
> I think, what Karthik meant by point 2 is something like below:
>
> <span jwcid="block1@Block">
>         <span jwcid="@Insert" value="ognl:testValue"/> </span>
>
> Here you can see that the content of the block has a binding to a
> property "testValue". So, which page will this binding be pointing to?
>
> - Navin
>
>


Re: Question regarding Block/RenderBlock

Posted by Robert Zeigler <ro...@scazdl.org>.
The root object for bindings is the page that contains the block, not 
the page that renders the block. That is, pageA contains the 
RenderBlock. pageB contains the Block to be rendered (below); testValue 
is a property in pageB.

So, how does your block in pageB access values from pageA?
Via the "Inserter" parameter of the Block component. For instance:

<!-- part of pageA -->
<div jwcid="@RenderBlock" block="ognl:components.myBlock" foo="ognl:bar" />

<!-- part of pageB. Note that "components" refers to the "components" 
property of pageB. -->
<div jwcid="MyBlock@Block">
   <span jwcid="@Insert" 
value="ognl:components.MyBlock.inserter.bindings['foo'].value" />
</div>


Ugly? Yes. But it works.
I highly recommend moving the property path to java, so you'd have:

value="ognl:theValue"

in the template, and:

.java
public Object getTheValue() {
   return 
((Block)getComponent("MyBlock")).getInserter().getBinding("foo").getValue();
}

Robert

PS: Note that I'm still very much a tap3 user; there's probably some 
pretty way to inject the value in tap4 that I'm entirely unaware of. :)


Karthik N wrote:
> Hi Navin,
> 
> You are right.  That is exactly my doubt/question.  How do OGNL bindings
> work for nested components inside a Block that is a part of a different 
> page
> and NOT the page that is currently being rendered.
> 
> Thanks, Karthik
> 
> On 11/9/06, B.S.Navin <bs...@effigent.net> wrote:
> 
>>
>> Hi Firas,
>>
>> I think, what Karthik meant by point 2 is something like below:
>>
>> <span jwcid="block1@Block">
>>         <span jwcid="@Insert" value="ognl:testValue"/>
>> </span>
>>
>> Here you can see that the content of the block has a binding to a
>> property "testValue". So, which page will this binding be pointing to?
>>
>> - Navin
>>
>>
> 



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


Re: Question regarding Block/RenderBlock

Posted by Karthik N <ka...@gmail.com>.
Hi Navin,

You are right.  That is exactly my doubt/question.  How do OGNL bindings
work for nested components inside a Block that is a part of a different page
and NOT the page that is currently being rendered.

Thanks, Karthik

On 11/9/06, B.S.Navin <bs...@effigent.net> wrote:
>
> Hi Firas,
>
> I think, what Karthik meant by point 2 is something like below:
>
> <span jwcid="block1@Block">
>         <span jwcid="@Insert" value="ognl:testValue"/>
> </span>
>
> Here you can see that the content of the block has a binding to a
> property "testValue". So, which page will this binding be pointing to?
>
> - Navin
>
>

Re: Question regarding Block/RenderBlock

Posted by "B.S.Navin" <bs...@effigent.net>.
Hi Firas,

I think, what Karthik meant by point 2 is something like below:

<span jwcid="block1@Block">
	<span jwcid="@Insert" value="ognl:testValue"/>
</span>

Here you can see that the content of the block has a binding to a  
property "testValue". So, which page will this binding be pointing to?

- Navin

On 09-Nov-06, at 2:32 PM, Firas Adiler wrote:

>  Hi Karthik,
>
> Q1) How does getting components from a different page affect the
> render/rewind cycle of the current page?
> A1) Doesn't affect the current page AFAIK. But should the included  
> block
> need any initialization/cleanup code, these has to go in
> pageAttached/pageDetached (not in pageBeginRender/pageEndRender) of  
> the page
> where the block was declared.
>
> Q2) What if the Block that comes from another page has some ognl  
> bindings...
> A2) Not really sure what you mean. The Block-component neither use any
> parameters nor allow any informal parameters.
>
> Q3) What are the best use-cases for such usage?
> A3) Whenever you need to reuse some dynamic/static html, it's kind of
> "include" directive in JSP.
>
> Regards,
>
> </Firas>
>
> -----Original Message-----
> From: Karthik N [mailto:karthik.nar@gmail.com]
> Sent: Wednesday, November 08, 2006 3:19 AM
> To: Tapestry users
> Subject: Re: Question regarding Block/RenderBlock
>
> Hi James and Firas,
>
> Yes I'm seeing a little light now :)
>
> 1) How does getting components from a different page affect the
> render/rewind cycle of the current page?
> 2) What if the Block that comes from another page has some ognl  
> bindings.
> How do those get resolved, as I'm now on an entirely different page?
> 3) What are the best use-cases for such usage?
>
> Thanks, Karthik
>
> On 11/8/06, Firas Adiler <ta...@idigna.com> wrote:
>>
>> Hi,
>>
>> There's IMO an easier way.
>>
>> Assume
>>         HtmlBlocks - the page containing the external block(s)
>>         ClientPage - the page that uses those external blocks
>>
>> In your ClientPage.page you write:
>> <inject property="exBlocks" type="page" object="HtmlBlocks" />
>>
>> And to access these blocks you write:
>> ognl:exBlocks.components.theNameOfTheBlock
>>
>> Hope this helps,
>>
>> </Firas>
>>
>>
>> -----Original Message-----
>> From: James Carman [mailto:james@carmanconsulting.com]
>> Sent: Tuesday, November 07, 2006 1:11 PM
>> To: Tapestry users
>> Subject: Re: Question regarding Block/RenderBlock
>>
>> You can create a page that has a bunch of @Blocks in it and you can
>> use those blocks in other pages.  We do that in Trails and it works
>> quite nicely.  Check out the  
>> org.apache.tapestry.util.ComponentAddress
>> class.  It allows you to "look up" components on other pages.  So,  
>> you
>> can use it this way...
>>
>> public Block getReusableBlockFromAnotherPage() {
>>   ComponentAddress addr = new ComponentAddress(
>> "MyReusableBlocksPage", "myReusableBlock" );
>>   return ( Block )addr.findComponent(getRequestCycle());
>> }
>>
>> In your page, you'd do this:
>>
>> <span jwcid="@RenderBlock" block="ognl:reusableBlockFromAnotherPage"
>> />
>>
>> This is off the top of my head, so the syntax might not be exactly
>> correct, but you get the general idea I hope.  Hope that helps!
>>
>> On 11/6/06, Karthik N <ka...@gmail.com> wrote:
>>> Hello,
>>>
>>> "RenderBlock does not mandate that the Block being rendered be
>>> contained within the page being rendered"
>>>
>>> I have seen this statement at so many places - but I am looking for
>>> an example/explanation of how to do it.
>>>
>>> Any pointers?
>>>
>>> Thanks, Karthik
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> 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


RE: Question regarding Block/RenderBlock

Posted by Firas Adiler <ta...@idigna.com>.
 Hi Karthik,

Q1) How does getting components from a different page affect the
render/rewind cycle of the current page?
A1) Doesn't affect the current page AFAIK. But should the included block
need any initialization/cleanup code, these has to go in
pageAttached/pageDetached (not in pageBeginRender/pageEndRender) of the page
where the block was declared.

Q2) What if the Block that comes from another page has some ognl bindings...
A2) Not really sure what you mean. The Block-component neither use any
parameters nor allow any informal parameters.

Q3) What are the best use-cases for such usage?
A3) Whenever you need to reuse some dynamic/static html, it's kind of
"include" directive in JSP.

Regards,

</Firas>

-----Original Message-----
From: Karthik N [mailto:karthik.nar@gmail.com] 
Sent: Wednesday, November 08, 2006 3:19 AM
To: Tapestry users
Subject: Re: Question regarding Block/RenderBlock

Hi James and Firas,

Yes I'm seeing a little light now :)

1) How does getting components from a different page affect the
render/rewind cycle of the current page?
2) What if the Block that comes from another page has some ognl bindings.
How do those get resolved, as I'm now on an entirely different page?
3) What are the best use-cases for such usage?

Thanks, Karthik

On 11/8/06, Firas Adiler <ta...@idigna.com> wrote:
>
> Hi,
>
> There's IMO an easier way.
>
> Assume
>         HtmlBlocks - the page containing the external block(s)
>         ClientPage - the page that uses those external blocks
>
> In your ClientPage.page you write:
> <inject property="exBlocks" type="page" object="HtmlBlocks" />
>
> And to access these blocks you write:
> ognl:exBlocks.components.theNameOfTheBlock
>
> Hope this helps,
>
> </Firas>
>
>
> -----Original Message-----
> From: James Carman [mailto:james@carmanconsulting.com]
> Sent: Tuesday, November 07, 2006 1:11 PM
> To: Tapestry users
> Subject: Re: Question regarding Block/RenderBlock
>
> You can create a page that has a bunch of @Blocks in it and you can 
> use those blocks in other pages.  We do that in Trails and it works 
> quite nicely.  Check out the org.apache.tapestry.util.ComponentAddress
> class.  It allows you to "look up" components on other pages.  So, you 
> can use it this way...
>
> public Block getReusableBlockFromAnotherPage() {
>   ComponentAddress addr = new ComponentAddress( 
> "MyReusableBlocksPage", "myReusableBlock" );
>   return ( Block )addr.findComponent(getRequestCycle());
> }
>
> In your page, you'd do this:
>
> <span jwcid="@RenderBlock" block="ognl:reusableBlockFromAnotherPage" 
> />
>
> This is off the top of my head, so the syntax might not be exactly 
> correct, but you get the general idea I hope.  Hope that helps!
>
> On 11/6/06, Karthik N <ka...@gmail.com> wrote:
> > Hello,
> >
> > "RenderBlock does not mandate that the Block being rendered be 
> > contained within the page being rendered"
> >
> > I have seen this statement at so many places - but I am looking for 
> > an example/explanation of how to do it.
> >
> > Any pointers?
> >
> > Thanks, Karthik
> >
> >
>
>
> ---------------------------------------------------------------------
> 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: Question regarding Block/RenderBlock

Posted by Karthik N <ka...@gmail.com>.
Hi James and Firas,

Yes I'm seeing a little light now :)

1) How does getting components from a different page affect the
render/rewind cycle of the current page?
2) What if the Block that comes from another page has some ognl bindings.
How do those get resolved, as I'm now on an entirely different page?
3) What are the best use-cases for such usage?

Thanks, Karthik

On 11/8/06, Firas Adiler <ta...@idigna.com> wrote:
>
> Hi,
>
> There's IMO an easier way.
>
> Assume
>         HtmlBlocks - the page containing the external block(s)
>         ClientPage - the page that uses those external blocks
>
> In your ClientPage.page you write:
> <inject property="exBlocks" type="page" object="HtmlBlocks" />
>
> And to access these blocks you write:
> ognl:exBlocks.components.theNameOfTheBlock
>
> Hope this helps,
>
> </Firas>
>
>
> -----Original Message-----
> From: James Carman [mailto:james@carmanconsulting.com]
> Sent: Tuesday, November 07, 2006 1:11 PM
> To: Tapestry users
> Subject: Re: Question regarding Block/RenderBlock
>
> You can create a page that has a bunch of @Blocks in it and you can use
> those blocks in other pages.  We do that in Trails and it works quite
> nicely.  Check out the org.apache.tapestry.util.ComponentAddress
> class.  It allows you to "look up" components on other pages.  So, you can
> use it this way...
>
> public Block getReusableBlockFromAnotherPage() {
>   ComponentAddress addr = new ComponentAddress( "MyReusableBlocksPage",
> "myReusableBlock" );
>   return ( Block )addr.findComponent(getRequestCycle());
> }
>
> In your page, you'd do this:
>
> <span jwcid="@RenderBlock" block="ognl:reusableBlockFromAnotherPage" />
>
> This is off the top of my head, so the syntax might not be exactly
> correct,
> but you get the general idea I hope.  Hope that helps!
>
> On 11/6/06, Karthik N <ka...@gmail.com> wrote:
> > Hello,
> >
> > "RenderBlock does not mandate that the Block being rendered be
> > contained within the page being rendered"
> >
> > I have seen this statement at so many places - but I am looking for an
> > example/explanation of how to do it.
> >
> > Any pointers?
> >
> > Thanks, Karthik
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

RE: Question regarding Block/RenderBlock

Posted by Firas Adiler <ta...@idigna.com>.
Hi,

There's IMO an easier way.

Assume
	HtmlBlocks - the page containing the external block(s)
	ClientPage - the page that uses those external blocks
 
In your ClientPage.page you write:
<inject property="exBlocks" type="page" object="HtmlBlocks" />

And to access these blocks you write:
ognl:exBlocks.components.theNameOfTheBlock

Hope this helps,

</Firas>


-----Original Message-----
From: James Carman [mailto:james@carmanconsulting.com] 
Sent: Tuesday, November 07, 2006 1:11 PM
To: Tapestry users
Subject: Re: Question regarding Block/RenderBlock

You can create a page that has a bunch of @Blocks in it and you can use
those blocks in other pages.  We do that in Trails and it works quite
nicely.  Check out the org.apache.tapestry.util.ComponentAddress
class.  It allows you to "look up" components on other pages.  So, you can
use it this way...

public Block getReusableBlockFromAnotherPage() {
  ComponentAddress addr = new ComponentAddress( "MyReusableBlocksPage",
"myReusableBlock" );
  return ( Block )addr.findComponent(getRequestCycle());
}

In your page, you'd do this:

<span jwcid="@RenderBlock" block="ognl:reusableBlockFromAnotherPage" />

This is off the top of my head, so the syntax might not be exactly correct,
but you get the general idea I hope.  Hope that helps!

On 11/6/06, Karthik N <ka...@gmail.com> wrote:
> Hello,
>
> "RenderBlock does not mandate that the Block being rendered be 
> contained within the page being rendered"
>
> I have seen this statement at so many places - but I am looking for an 
> example/explanation of how to do it.
>
> Any pointers?
>
> Thanks, Karthik
>
>


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


Re: Question regarding Block/RenderBlock

Posted by James Carman <ja...@carmanconsulting.com>.
You can create a page that has a bunch of @Blocks in it and you can
use those blocks in other pages.  We do that in Trails and it works
quite nicely.  Check out the org.apache.tapestry.util.ComponentAddress
class.  It allows you to "look up" components on other pages.  So, you
can use it this way...

public Block getReusableBlockFromAnotherPage()
{
  ComponentAddress addr = new ComponentAddress(
"MyReusableBlocksPage", "myReusableBlock" );
  return ( Block )addr.findComponent(getRequestCycle());
}

In your page, you'd do this:

<span jwcid="@RenderBlock" block="ognl:reusableBlockFromAnotherPage" />

This is off the top of my head, so the syntax might not be exactly
correct, but you get the general idea I hope.  Hope that helps!

On 11/6/06, Karthik N <ka...@gmail.com> wrote:
> Hello,
>
> "RenderBlock does not mandate that the Block being rendered be contained
> within the page being rendered"
>
> I have seen this statement at so many places - but I am looking for an
> example/explanation of how to do it.
>
> Any pointers?
>
> Thanks, Karthik
>
>

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