What you are trying to do is a no-go in tapestry (dynamic specification
of the component): tapestry is static structure, dynamic behavior.
BUT, you can still achieve the desired affect, and the trick is, in
fact, to use block/renderblock. You always render a block component with
a render block component. However, 1) the block to be rendered can be
obtained from virtually anywhere, and 2) the block to be rendered can
/contain/ virtually anything.
So, wrap your component(s) to be rendered inside of named blocks. Then
use renderblock to pick the appropriate block to render.
Something like:
blah.html:
<div jwcid="@RenderBlock" block="ognl:block"/>
blah.java
public Block getBlock() {
IPage page = getRequestCycle().getPage(lookupAppropriatePageName());
return page.getComponent(lookupAppropriateBlockName());
}
someotherpage.html
<block jwcid="[EMAIL PROTECTED]">
<!-- put here your html, or your custom components, or whatever the
heck you want... this is where the "dynamic" portion would go...
whatever you were trying to specify as a component type string
before.
-->
</block>
So, you have only one "application page", which is fine.
Now any other "pages" you create simply use BasePage as their class,
and they serve only as component holders.
Voila. Static structures, but dynamic content, and no
if's required.
Robert
Stephen Todd wrote:
> I am doing things here in a way that is correspondingbackward conceptually to
> tapestry. I only have one page in my app and the navigation is based on
> state and not page location. This is because the app navigation and
> structure is largely dynamic. It would seem like it shouldn't be too
> complicated to create a Component to do this. It would be like the
> WOSwitchComponent in WebObjects, but then again, I am just learning
> tapestry and don't know the request-response cycle here.
>
> One reason that the approach mentioned won't work, is that I don't want
> to have to know the component ahead of time, otherwise adding a new
> option to the list will become a headache. This list is currently around
> 10 and it will continue to grow. Any pointers to help me make this
> component would be great, but if not, I'll figure something out somehow.
>
> Thanks!
>
> Steve
>
>
> Robert Zeigler wrote:
>
>> As Ben Dotte pointed out already, the "tapestry" way of doing this is to
>> use block/render block. The nice thing about this approach is that the
>> blocks you define don't even have to be on the same page as the render
>> block (although if you start defining blocks on other pages, avoid using
>> page render listeners to initialize variables for those blocks).
>>
>> You can even pass parameters on; you can put the parameters into the
>> render block as informal parameters, and get at them via the "inserter"
>> property of the block.
>>
>> So..
>>
>> in the .html:
>>
>> <span jwcid="area"/>
>>
>> In the .jwc:
>>
>> <component id="area" type="RenderBlock">
>> <binding name="block" expression="theBlock"/>
>> <binding name="foo" expression="bar"/>
>> </component>
>>
>> .java:
>>
>> public Block getTheBlock() {
>> return getRequestCycle()
>> .getPage("blockpagex").getComponent("blockx");
>> }
>>
>>
>> Then, on blockpagex, you might have:
>> <div jwcid="[EMAIL PROTECTED]">
>> <!-- render some stuff -->
>> <!-- note that the expression path I've got here is off the top of
>> my head, and you'd want to double check it for accuracy. :) -->
>> <span jwcid="@Insert" value="ognl:components.blockx.inserter.foo"/>
>> </div>
>>
>> Robert
>>
>> Stephen Todd wrote:
>>
>>
>>> I'm trying to specify which component to use dynamically, but I think
>>> what I want to do is outside of conventions. I wanted to do something
>>> like the following.
>>>
>>> in the .html
>>>
>>> <span jwcid="area"/>
>>>
>>> in the .jwc
>>>
>>> <component id="area" type="ognl:componentType"/>
>>>
>>> and in the .java
>>>
>>> public String getComponentType() {
>>> // some code
>>> return "@" + componentType; // ie. MyCoolArea
>>> }
>>>
>>> (This isn't the real code)
>>>
>>> I know I could just line up a bunch of if's but that seems wrong and
>>> inefficient. I know in the example above that it is trying to find
>>> 'componentType' in the namespace 'ognl', but I really just want to pass
>>> a string to specifiy the component.
>>>
>>> Thanks,
>>>
>>> Steve
>>>
>>> ---------------------------------------------------------------------
>>> 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]